@catamorphic/fastify-plugin 0.0.0-stage → 0.1.0-alpha.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (160) hide show
  1. package/LICENSE.txt +202 -0
  2. package/NOTICE.txt +32 -0
  3. package/README.md +143 -2
  4. package/dist/app-presentation-tools.d.ts +4 -0
  5. package/dist/app-presentation-tools.d.ts.map +1 -0
  6. package/dist/app.d.ts +27 -0
  7. package/dist/app.d.ts.map +1 -0
  8. package/dist/chunk-baagvvm3.js +164 -0
  9. package/dist/chunk-baagvvm3.js.map +10 -0
  10. package/dist/http-identity.d.ts +52 -0
  11. package/dist/http-identity.d.ts.map +1 -0
  12. package/dist/hung-up.d.ts +7 -0
  13. package/dist/hung-up.d.ts.map +1 -0
  14. package/dist/index.d.ts +11 -0
  15. package/dist/index.d.ts.map +1 -0
  16. package/dist/index.js +10884 -0
  17. package/dist/index.js.map +56 -0
  18. package/dist/mcp-shared.d.ts +117 -0
  19. package/dist/mcp-shared.d.ts.map +1 -0
  20. package/dist/mcp.d.ts +6 -0
  21. package/dist/mcp.d.ts.map +1 -0
  22. package/dist/mcp.js +13 -0
  23. package/dist/mcp.js.map +9 -0
  24. package/dist/plugin.d.ts +113 -0
  25. package/dist/plugin.d.ts.map +1 -0
  26. package/dist/project-capabilities.d.ts +25 -0
  27. package/dist/project-capabilities.d.ts.map +1 -0
  28. package/dist/project-mcp-program.d.ts +15 -0
  29. package/dist/project-mcp-program.d.ts.map +1 -0
  30. package/dist/project-mcp-surface.d.ts +16 -0
  31. package/dist/project-mcp-surface.d.ts.map +1 -0
  32. package/dist/request-logging.d.ts +18 -0
  33. package/dist/request-logging.d.ts.map +1 -0
  34. package/dist/routes/agent-capabilities.d.ts +4 -0
  35. package/dist/routes/agent-capabilities.d.ts.map +1 -0
  36. package/dist/routes/agent.d.ts +4 -0
  37. package/dist/routes/agent.d.ts.map +1 -0
  38. package/dist/routes/apps-mcp.d.ts +4 -0
  39. package/dist/routes/apps-mcp.d.ts.map +1 -0
  40. package/dist/routes/apps.d.ts +12 -0
  41. package/dist/routes/apps.d.ts.map +1 -0
  42. package/dist/routes/client-runners.d.ts +11 -0
  43. package/dist/routes/client-runners.d.ts.map +1 -0
  44. package/dist/routes/code-hosts.d.ts +11 -0
  45. package/dist/routes/code-hosts.d.ts.map +1 -0
  46. package/dist/routes/connection-mcp.d.ts +10 -0
  47. package/dist/routes/connection-mcp.d.ts.map +1 -0
  48. package/dist/routes/connections.d.ts +4 -0
  49. package/dist/routes/connections.d.ts.map +1 -0
  50. package/dist/routes/documents.d.ts +11 -0
  51. package/dist/routes/documents.d.ts.map +1 -0
  52. package/dist/routes/environments.d.ts +4 -0
  53. package/dist/routes/environments.d.ts.map +1 -0
  54. package/dist/routes/git-gateway.d.ts +21 -0
  55. package/dist/routes/git-gateway.d.ts.map +1 -0
  56. package/dist/routes/http-gateway.d.ts +13 -0
  57. package/dist/routes/http-gateway.d.ts.map +1 -0
  58. package/dist/routes/me.d.ts +12 -0
  59. package/dist/routes/me.d.ts.map +1 -0
  60. package/dist/routes/memberships.d.ts +12 -0
  61. package/dist/routes/memberships.d.ts.map +1 -0
  62. package/dist/routes/model-gateway.d.ts +12 -0
  63. package/dist/routes/model-gateway.d.ts.map +1 -0
  64. package/dist/routes/notifications.d.ts +4 -0
  65. package/dist/routes/notifications.d.ts.map +1 -0
  66. package/dist/routes/parse.d.ts +5 -0
  67. package/dist/routes/parse.d.ts.map +1 -0
  68. package/dist/routes/personal-environment.d.ts +13 -0
  69. package/dist/routes/personal-environment.d.ts.map +1 -0
  70. package/dist/routes/plugins.d.ts +4 -0
  71. package/dist/routes/plugins.d.ts.map +1 -0
  72. package/dist/routes/project-mcp.d.ts +25 -0
  73. package/dist/routes/project-mcp.d.ts.map +1 -0
  74. package/dist/routes/projects.d.ts +4 -0
  75. package/dist/routes/projects.d.ts.map +1 -0
  76. package/dist/routes/publications.d.ts +15 -0
  77. package/dist/routes/publications.d.ts.map +1 -0
  78. package/dist/routes/run-errors.d.ts +8 -0
  79. package/dist/routes/run-errors.d.ts.map +1 -0
  80. package/dist/routes/runs.d.ts +4 -0
  81. package/dist/routes/runs.d.ts.map +1 -0
  82. package/dist/routes/session-artifacts.d.ts +27 -0
  83. package/dist/routes/session-artifacts.d.ts.map +1 -0
  84. package/dist/routes/session-mailboxes.d.ts +4 -0
  85. package/dist/routes/session-mailboxes.d.ts.map +1 -0
  86. package/dist/routes/session-previews.d.ts +40 -0
  87. package/dist/routes/session-previews.d.ts.map +1 -0
  88. package/dist/routes/session-terminals.d.ts +15 -0
  89. package/dist/routes/session-terminals.d.ts.map +1 -0
  90. package/dist/routes/triggers.d.ts +20 -0
  91. package/dist/routes/triggers.d.ts.map +1 -0
  92. package/dist/routes/watchers.d.ts +4 -0
  93. package/dist/routes/watchers.d.ts.map +1 -0
  94. package/dist/routes/webhooks.d.ts +11 -0
  95. package/dist/routes/webhooks.d.ts.map +1 -0
  96. package/dist/routes/workflow-enablements.d.ts +4 -0
  97. package/dist/routes/workflow-enablements.d.ts.map +1 -0
  98. package/dist/routes/workflows.d.ts +4 -0
  99. package/dist/routes/workflows.d.ts.map +1 -0
  100. package/dist/schemas.d.ts +17776 -0
  101. package/dist/schemas.d.ts.map +1 -0
  102. package/dist/session-artifact-tools.d.ts +5 -0
  103. package/dist/session-artifact-tools.d.ts.map +1 -0
  104. package/dist/session-event-stream.d.ts +45 -0
  105. package/dist/session-event-stream.d.ts.map +1 -0
  106. package/dist/spa.d.ts +24 -0
  107. package/dist/spa.d.ts.map +1 -0
  108. package/dist/telemetry.d.ts +4 -0
  109. package/dist/telemetry.d.ts.map +1 -0
  110. package/package.json +73 -4
  111. package/src/app-presentation-tools.ts +46 -0
  112. package/src/app.ts +115 -0
  113. package/src/http-identity.ts +145 -0
  114. package/src/hung-up.ts +13 -0
  115. package/src/index.ts +25 -0
  116. package/src/mcp-shared.ts +331 -0
  117. package/src/mcp.ts +10 -0
  118. package/src/plugin.ts +332 -0
  119. package/src/project-capabilities.ts +153 -0
  120. package/src/project-mcp-program.ts +607 -0
  121. package/src/project-mcp-surface.ts +881 -0
  122. package/src/request-logging.ts +47 -0
  123. package/src/routes/agent-capabilities.ts +109 -0
  124. package/src/routes/agent.ts +1566 -0
  125. package/src/routes/apps-mcp.ts +303 -0
  126. package/src/routes/apps.ts +692 -0
  127. package/src/routes/client-runners.ts +251 -0
  128. package/src/routes/code-hosts.ts +247 -0
  129. package/src/routes/connection-mcp.ts +135 -0
  130. package/src/routes/connections.ts +494 -0
  131. package/src/routes/documents.ts +538 -0
  132. package/src/routes/environments.ts +72 -0
  133. package/src/routes/git-gateway.ts +106 -0
  134. package/src/routes/http-gateway.ts +141 -0
  135. package/src/routes/me.ts +122 -0
  136. package/src/routes/memberships.ts +173 -0
  137. package/src/routes/model-gateway.ts +134 -0
  138. package/src/routes/notifications.ts +101 -0
  139. package/src/routes/parse.ts +32 -0
  140. package/src/routes/personal-environment.ts +146 -0
  141. package/src/routes/plugins.ts +341 -0
  142. package/src/routes/project-mcp.ts +394 -0
  143. package/src/routes/projects.ts +708 -0
  144. package/src/routes/publications.ts +222 -0
  145. package/src/routes/run-errors.ts +86 -0
  146. package/src/routes/runs.ts +253 -0
  147. package/src/routes/session-artifacts.ts +293 -0
  148. package/src/routes/session-mailboxes.ts +80 -0
  149. package/src/routes/session-previews.ts +224 -0
  150. package/src/routes/session-terminals.ts +209 -0
  151. package/src/routes/triggers.ts +241 -0
  152. package/src/routes/watchers.ts +94 -0
  153. package/src/routes/webhooks.ts +171 -0
  154. package/src/routes/workflow-enablements.ts +331 -0
  155. package/src/routes/workflows.ts +323 -0
  156. package/src/schemas.ts +2735 -0
  157. package/src/session-artifact-tools.ts +170 -0
  158. package/src/session-event-stream.ts +122 -0
  159. package/src/spa.ts +135 -0
  160. package/src/telemetry.ts +93 -0
package/LICENSE.txt 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/NOTICE.txt ADDED
@@ -0,0 +1,32 @@
1
+ Catamorphic
2
+ Copyright 2026 The Catamorphic Authors
3
+
4
+ This product is licensed under the Apache License, Version 2.0 (the
5
+ "License"); see the LICENSE file for the full text.
6
+
7
+ --------------------------------------------------------------------------------
8
+ This product includes third-party software under separate license terms:
9
+
10
+ command-score
11
+ apps/desktop/src/renderer/lib/command-score.ts is a port of Superhuman's
12
+ command-score fuzzy matcher.
13
+
14
+ Copyright (c) 2016 Superhuman
15
+
16
+ Permission is hereby granted, free of charge, to any person obtaining a copy
17
+ of this software and associated documentation files (the "Software"), to deal
18
+ in the Software without restriction, including without limitation the rights
19
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
20
+ copies of the Software, and to permit persons to whom the Software is
21
+ furnished to do so, subject to the following conditions:
22
+
23
+ The above copyright notice and this permission notice shall be included in all
24
+ copies or substantial portions of the Software.
25
+
26
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
29
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
30
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
31
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,144 @@
1
- # Temporary Holding Version
1
+ # @catamorphic/fastify-plugin
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Mountable Fastify plugin exposing Catamorphic's project, document, git, agent,
4
+ app, workflow, run, connection, role, membership, publication, and MCP surfaces
5
+ with Zod-validated routes and a generated OpenAPI spec consumed by
6
+ `@catamorphic/api-client`.
7
+
8
+ ## Mount on the host's Fastify server
9
+
10
+ ```ts
11
+ import { catamorphicPlugin } from "@catamorphic/fastify-plugin";
12
+
13
+ app.register(catamorphicPlugin, {
14
+ core: catamorphic.core, // built with @catamorphic/server-sdk
15
+ prefix: "/api", // the generated api-client expects /api
16
+ identity: async (request) => {
17
+ // Who is calling — from YOUR session. See "Identity" below.
18
+ const session = await verifySession(request);
19
+ return session
20
+ ? { tenantId: session.orgId, externalUserId: session.userId }
21
+ : null;
22
+ },
23
+ });
24
+ ```
25
+
26
+ The plugin is fully encapsulated:
27
+
28
+ - Sets Zod validator/serializer compilers and an error handler for its own scope only.
29
+ - Registers **no CORS** — the host owns cross-origin policy.
30
+ - Route URLs are prefix-relative; mount anywhere, but `@catamorphic/api-client`'s generated paths assume `/api`.
31
+
32
+ ## Runs
33
+
34
+ There is one Runs route family for every Workflow:
35
+
36
+ - `POST /api/projects/:projectId/workflows/:name/runs` triggers a Run of the deployed commit (async).
37
+ - `POST /api/projects/:projectId/workflows/:name/calls` calls a workflow synchronously — driven inline until it settles or reaches a durable wait; answers `completed | failed | suspended` (with `runId` to poll).
38
+ - `GET /api/projects/:projectId/workflows/:name/runs` lists Runs.
39
+ - `GET /api/runs/:runId` and `/api/runs/:runId/*` expose detail and capability-driven controls.
40
+
41
+ Boundaries, batch scopes, pauses, and item progress are capabilities/details on
42
+ the canonical Workflow and Run models. They do not get separate route families.
43
+ Run list and detail responses expose every Batch processing scope as ordered
44
+ `batchScopes`, including failed and canceled attempts, so hosts can inspect
45
+ items by `workflowStepAttemptId` after the Run is terminal.
46
+ Pause and resume return `409` when their current Run capability is unavailable;
47
+ repeating an operation after it already reached its target paused/running state
48
+ is idempotent.
49
+
50
+ Workflow list and detail routes accept `?ref=<git-ref>`. Workflow detail always
51
+ includes `projectFiles` and `allFiles`; public workflow responses omit internal
52
+ parser execution descriptors.
53
+
54
+ ## Identity
55
+
56
+ The plugin has exactly one identity mechanism: the required `identity`
57
+ resolver. It runs on every request and returns the caller's identity or
58
+ `null` (→ 401). There are no defaults and no headers are read unless you opt
59
+ in.
60
+
61
+ ```ts
62
+ app.register(catamorphicPlugin, {
63
+ core,
64
+ prefix: "/api",
65
+ identity: async (request) => {
66
+ const session = await verifySession(request);
67
+ if (!session) return null;
68
+ const base = { tenantId: session.orgId, externalUserId: session.userId };
69
+ if (session.isEmployee)
70
+ return {
71
+ ...base,
72
+ scope: [
73
+ { kind: "agent", projectId: BRAIN, name: "*" },
74
+ { kind: "workflow", projectId: BRAIN, name: "*" },
75
+ { kind: "app", projectId: BRAIN, name: "*" },
76
+ ],
77
+ projectPermissions: [{ projectId: BRAIN, permission: "program:write" }],
78
+ };
79
+ return { ...base, scope: await entitlementsFor(session.userId) }; // viewer
80
+ },
81
+ });
82
+ ```
83
+
84
+ - A **root** identity (no `scope`) reaches every project and surface — a host's service calls, the desktop's own local projects.
85
+ - A **scoped** identity may reach exactly the listed artifacts: `{ kind: "app", projectId, name }` (the app's document plus its active version's frozen workflow set), `{ kind: "workflow", projectId, name }`, `{ kind: "agent", projectId, name, toolPolicies? }` (chat sessions on a committed project agent) or `{ kind: "document", projectId, path, access? }` (a file or `dir/**` subtree; the project store is reachable only this way), and nothing else. An `app`, `workflow` or `agent` ref may name `"*"` for every one. Denials are a uniform 403.
86
+ - What a scoped identity may do beyond using artifacts is `projectPermissions: [{ projectId, permission }]`: `thing:action` names over `program` (read, write, publish), `secrets`, `automations`, `webhooks`, `runs`, `sessions`, `memberships`, `roles` and `publications` (read, write). `write` and `publish` imply `read` on the same thing; grants may be `thing:*` or `*`. See INTEGRATION.md for the full table.
87
+ - Most hosts do not hand-write scopes: commit `.work/roles/<slug>.json` in the project and resolve members through `core.memberships.identityFor(...)` (the stock table) or `resolveRoles(core, { roles, grants })`; members with a host-issued token use `identityFromBearer(verify)`. See INTEGRATION.md "Roles as files".
88
+ - Role permissions use the namespaced `thing:action` form. Core enforces its
89
+ own names (ADR 0158); unknown valid names such as `brain:maintain` grant no
90
+ framework authority but remain available to explicit embedder policy and
91
+ project-authored presentation.
92
+ - Hosts whose auth terminates in front of the plugin (gateway, proxy) can pass `identityFromHeaders()`, which reads `X-Catamorphic-Tenant-Id` and `X-External-User-Id`. Never expose such a mount to browsers directly.
93
+
94
+ `GET /api/me` is the client capability document. It returns the current
95
+ identity summary, each visible project's effective permissions (wildcards and
96
+ implications expanded), source (for holders of `program:read`), artifact refs
97
+ and roles, and the host's enabled feature switches. Clients should shape
98
+ their UI from this response rather than probing forbidden routes.
99
+
100
+ ## Agent sessions
101
+
102
+ Sessions carry durable source provenance (`desktop`, `mobile`, `slack`,
103
+ `claude`, `mcp`, or `api`), hierarchy, fork lineage, visibility, archive,
104
+ attention, activity, and todo state in one schema. First-class subsession
105
+ routes create, list, wait for, and interrupt delegated child sessions. Archive
106
+ is recursive and can return a typed 409 impact requiring confirmation before
107
+ it stops active turns, Watchers, or processes; unarchive restores the tree.
108
+ Do not create a parallel client-only archive or subagent model.
109
+
110
+ ## Workflow enablements
111
+
112
+ Role access does not authorize unattended execution. The workflow-enablement
113
+ routes preview the exact deployed commit and its trigger, agent, Environment,
114
+ and connection requirements, then bind explicit member consent to a digest.
115
+ Enablements have disable, reenable, and deployment-update operations.
116
+ Connection authorization can resume the selected enablement but must not
117
+ bulk-enable compatible workflows.
118
+
119
+ ## Apps
120
+
121
+ Viewer-facing app routes (`view-state`, `guest`, `storage`, `calls/:workflow`,
122
+ `runs/:workflow`, `runs/:runId`) narrow the caller to that app structurally —
123
+ the URL names it, so an admin is confined to the app while inside it and a
124
+ viewer must be entitled to it. `AppMount` in `@catamorphic/ui` uses these
125
+ routes; nothing is claimed by the client.
126
+
127
+ ## Standalone app (sidecar / spec generation)
128
+
129
+ ```ts
130
+ import { createApp, identityFromHeaders } from "@catamorphic/fastify-plugin";
131
+
132
+ const app = createApp({ core, identity: identityFromHeaders() });
133
+ await app.listen({ port: 8500 });
134
+ // Swagger UI at /docs, API at /api/*
135
+ ```
136
+
137
+ ## Regenerating the API client
138
+
139
+ After changing routes or DTOs:
140
+
141
+ ```bash
142
+ bun run generate-spec # writes packages/api-client/openapi.json
143
+ cd ../api-client && bun run generate
144
+ ```
@@ -0,0 +1,4 @@
1
+ import type { CatamorphicCore, Identity } from "@catamorphic/core";
2
+ import type { SurfaceTool } from "./project-mcp-surface.js";
3
+ export declare function appPresentationTool(core: CatamorphicCore, identity: Identity, projectId: string): SurfaceTool;
4
+ //# sourceMappingURL=app-presentation-tools.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app-presentation-tools.d.ts","sourceRoot":"","sources":["../src/app-presentation-tools.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAGnE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAa5D,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,eAAe,EACrB,QAAQ,EAAE,QAAQ,EAClB,SAAS,EAAE,MAAM,GAChB,WAAW,CAwBb"}
package/dist/app.d.ts ADDED
@@ -0,0 +1,27 @@
1
+ import type { CatamorphicCore } from "@catamorphic/core";
2
+ import type { IdentityResolver } from "./http-identity.js";
3
+ import { type CatamorphicPluginOptions } from "./plugin.js";
4
+ export type { RouteContext } from "./plugin.js";
5
+ export interface AppConfig {
6
+ /**
7
+ * Wired catamorphic services. Required for any non-trivial route. When
8
+ * omitted (e.g. unit tests that only hit stub routes), project / run /
9
+ * workflow endpoints respond 503.
10
+ */
11
+ core?: CatamorphicCore;
12
+ /**
13
+ * Who is calling — see `CatamorphicPluginOptions.identity`. A sidecar that
14
+ * sits behind the host's own auth typically passes `identityFromHeaders()`.
15
+ */
16
+ identity: IdentityResolver;
17
+ /** Host feature switches; see `CatamorphicPluginOptions.features`. */
18
+ features?: CatamorphicPluginOptions["features"];
19
+ /** See `CatamorphicPluginOptions.publicApiBase`. */
20
+ publicApiBase?: string;
21
+ /** See `CatamorphicPluginOptions.projectMcp`. */
22
+ projectMcp?: CatamorphicPluginOptions["projectMcp"];
23
+ }
24
+ export declare function createApp(config: AppConfig): import("fastify").FastifyInstance<import("fastify").RawServerDefault, import("node:http").IncomingMessage, import("node:http").ServerResponse<import("node:http").IncomingMessage>, import("fastify").FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault> & PromiseLike<import("fastify").FastifyInstance<import("fastify").RawServerDefault, import("node:http").IncomingMessage, import("node:http").ServerResponse<import("node:http").IncomingMessage>, import("fastify").FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault>> & {
25
+ __linterBrands: 'SafePromiseLike';
26
+ };
27
+ //# sourceMappingURL=app.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AASzD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,KAAK,wBAAwB,EAAqB,MAAM,aAAa,CAAC;AAQ/E,YAAY,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,MAAM,WAAW,SAAS;IACxB;;;;OAIG;IACH,IAAI,CAAC,EAAE,eAAe,CAAC;IACvB;;;OAGG;IACH,QAAQ,EAAE,gBAAgB,CAAC;IAC3B,sEAAsE;IACtE,QAAQ,CAAC,EAAE,wBAAwB,CAAC,UAAU,CAAC,CAAC;IAChD,oDAAoD;IACpD,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,iDAAiD;IACjD,UAAU,CAAC,EAAE,wBAAwB,CAAC,YAAY,CAAC,CAAC;CACrD;AAwBD,wBAAgB,SAAS,CAAC,MAAM,EAAE,SAAS;;EAoD1C"}
@@ -0,0 +1,164 @@
1
+ // src/mcp-shared.ts
2
+ import { MCP_POLL_RUN_TOOL, RunNotFoundError } from "@catamorphic/core";
3
+ import { z } from "zod";
4
+ var SUPPORTED_PROTOCOL_VERSIONS = new Set([
5
+ "2024-11-05",
6
+ "2025-03-26",
7
+ "2025-06-18",
8
+ "2025-11-25"
9
+ ]);
10
+ var DEFAULT_PROTOCOL_VERSION = "2025-06-18";
11
+ function negotiateProtocolVersion(requested) {
12
+ return typeof requested === "string" && SUPPORTED_PROTOCOL_VERSIONS.has(requested) ? requested : DEFAULT_PROTOCOL_VERSION;
13
+ }
14
+
15
+ class McpRequestError2 extends Error {
16
+ code;
17
+ constructor(code, message) {
18
+ super(message);
19
+ this.code = code;
20
+ this.name = "McpRequestError";
21
+ }
22
+ }
23
+ async function handleMcpPost(reply, body, dispatch) {
24
+ const message = body;
25
+ if (!message || typeof message !== "object" || Array.isArray(message)) {
26
+ return rpcError(reply, null, -32600, "Expected a single JSON-RPC message");
27
+ }
28
+ if (message.id === undefined || message.id === null) {
29
+ return reply.status(202).send();
30
+ }
31
+ if (typeof message.method !== "string") {
32
+ return rpcError(reply, message.id, -32600, "Missing method");
33
+ }
34
+ try {
35
+ const result = await dispatch(message.method, message.params ?? {});
36
+ return rpcResult(reply, message.id, result);
37
+ } catch (error) {
38
+ if (error instanceof McpRequestError2) {
39
+ return rpcError(reply, message.id, error.code, error.message);
40
+ }
41
+ return rpcError(reply, message.id, -32603, error instanceof Error ? error.message : "Internal error");
42
+ }
43
+ }
44
+ function rpcResult(reply, id, result) {
45
+ return reply.header("content-type", "application/json").send({ jsonrpc: "2.0", id, result });
46
+ }
47
+ function rpcError(reply, id, code, message) {
48
+ return reply.header("content-type", "application/json").send({ jsonrpc: "2.0", id, error: { code, message } });
49
+ }
50
+ function toolValue(value) {
51
+ return {
52
+ content: [{ type: "text", text: JSON.stringify(value) ?? "null" }],
53
+ ...typeof value === "object" && value !== null && !Array.isArray(value) ? { structuredContent: value } : {}
54
+ };
55
+ }
56
+ function toolError2(message) {
57
+ return { content: [{ type: "text", text: message }], isError: true };
58
+ }
59
+ function forwardedTool(tool) {
60
+ return {
61
+ name: tool.name,
62
+ ...tool.title ? { title: tool.title } : {},
63
+ ...tool.description ? { description: tool.description } : {},
64
+ inputSchema: tool.inputSchema,
65
+ ...isObjectSchema(tool.outputSchema) ? { outputSchema: tool.outputSchema } : {},
66
+ ...tool.annotations ? { annotations: tool.annotations } : {}
67
+ };
68
+ }
69
+ var ForwardedToolResultSchema = z.looseObject({
70
+ content: z.array(z.unknown()),
71
+ structuredContent: z.unknown().optional()
72
+ });
73
+ function forwardedToolResult(result) {
74
+ const parsed = ForwardedToolResultSchema.safeParse(result);
75
+ if (!parsed.success)
76
+ return toolValue(result);
77
+ const { structuredContent, ...rest } = parsed.data;
78
+ if (structuredContent === undefined)
79
+ return rest;
80
+ if (isObject(structuredContent))
81
+ return { ...rest, structuredContent };
82
+ return rest.content.length > 0 ? rest : {
83
+ ...rest,
84
+ content: [{ type: "text", text: JSON.stringify(structuredContent) }]
85
+ };
86
+ }
87
+ function isObject(value) {
88
+ return typeof value === "object" && value !== null && !Array.isArray(value);
89
+ }
90
+ function isObjectSchema(schema) {
91
+ return isObject(schema) && schema.type === "object";
92
+ }
93
+ var POLL_RUN_TOOL = MCP_POLL_RUN_TOOL;
94
+ var POLL_RUN_TOOL_DEFINITION = {
95
+ name: POLL_RUN_TOOL,
96
+ annotations: { readOnlyHint: true },
97
+ description: "Poll a workflow run by its runId — one started asynchronously or one " + "that detached mid-call. Returns the run's status, output (once " + "completed), and batch progress.",
98
+ inputSchema: {
99
+ type: "object",
100
+ properties: { runId: { type: "string" } },
101
+ required: ["runId"]
102
+ }
103
+ };
104
+ async function callPollRunTool(core, identity, args) {
105
+ const runId = typeof args.runId === "string" ? args.runId : "";
106
+ try {
107
+ return toolValue(await fetchRunSnapshot(core, identity, runId));
108
+ } catch (error) {
109
+ if (error instanceof RunNotFoundError)
110
+ return toolError2("Run not found");
111
+ throw error;
112
+ }
113
+ }
114
+ async function fetchRunSnapshot(core, identity, runId) {
115
+ const run = await core.runs.get({ identity, runId });
116
+ const batch = run.batchScopes?.[0];
117
+ return {
118
+ runId: run.id,
119
+ status: run.status,
120
+ output: run.result ?? null,
121
+ error: run.error ?? null,
122
+ ...batch ? {
123
+ progress: {
124
+ discovered: batch.discovered,
125
+ succeeded: batch.succeeded,
126
+ failed: batch.failed,
127
+ skipped: batch.skipped
128
+ }
129
+ } : {}
130
+ };
131
+ }
132
+ var CallParamsSchema = z.object({
133
+ name: z.string().min(1),
134
+ arguments: z.record(z.string(), z.unknown()).default({})
135
+ });
136
+ function serveForwardedTools2(args) {
137
+ return handleMcpPost(args.reply, args.body, async (method, params) => {
138
+ switch (method) {
139
+ case "initialize":
140
+ return {
141
+ protocolVersion: negotiateProtocolVersion(params.protocolVersion),
142
+ capabilities: { tools: {} },
143
+ serverInfo: { name: args.serverName, version: "1" }
144
+ };
145
+ case "ping":
146
+ return {};
147
+ case "tools/list":
148
+ return { tools: (await args.listTools()).map(forwardedTool) };
149
+ case "tools/call": {
150
+ const call = CallParamsSchema.safeParse(params);
151
+ if (!call.success)
152
+ throw new McpRequestError2(-32602, "Invalid tool call");
153
+ return forwardedToolResult(await args.callTool(call.data));
154
+ }
155
+ default:
156
+ throw new McpRequestError2(-32601, "Method not found");
157
+ }
158
+ });
159
+ }
160
+
161
+ export { negotiateProtocolVersion, McpRequestError2, handleMcpPost, toolValue, toolError2, POLL_RUN_TOOL, POLL_RUN_TOOL_DEFINITION, callPollRunTool, serveForwardedTools2 };
162
+
163
+ //# debugId=74DF53EFD630A4A264756E2164756E21
164
+ //# sourceMappingURL=chunk-baagvvm3.js.map
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/mcp-shared.ts"],
4
+ "sourcesContent": [
5
+ "import type { CatamorphicCore, Identity } from \"@catamorphic/core\";\nimport { MCP_POLL_RUN_TOOL, RunNotFoundError } from \"@catamorphic/core\";\nimport type { FastifyReply } from \"fastify\";\nimport { z } from \"zod\";\n\n/**\n * The JSON-RPC / MCP plumbing shared by the plugin's MCP endpoints — the\n * apps server (`/projects/:id/apps-mcp`), the workflow-tools server\n * (`/projects/:id/mcp`) and the connection broker (`/connection-mcp`) —\n * and by hosts that forward MCP servers of their own. All are stateless\n * Streamable-HTTP handlers speaking the `initialize`-handshake protocol era\n * (≤2025-11-25): requests are independent, no sessions, notifications\n * answered with a bare 202.\n */\n\nexport interface JsonRpcMessage {\n jsonrpc?: string;\n id?: number | string | null;\n method?: string;\n params?: Record<string, unknown>;\n}\n\nexport const SUPPORTED_PROTOCOL_VERSIONS = new Set([\n \"2024-11-05\",\n \"2025-03-26\",\n \"2025-06-18\",\n \"2025-11-25\",\n]);\nexport const DEFAULT_PROTOCOL_VERSION = \"2025-06-18\";\n\n/** The requested revision when supported, our default otherwise. */\nexport function negotiateProtocolVersion(requested: unknown): string {\n return typeof requested === \"string\" &&\n SUPPORTED_PROTOCOL_VERSIONS.has(requested)\n ? requested\n : DEFAULT_PROTOCOL_VERSION;\n}\n\n/** A dispatch failure that should ride a specific JSON-RPC error code. */\nexport class McpRequestError extends Error {\n constructor(\n readonly code: number,\n message: string,\n ) {\n super(message);\n this.name = \"McpRequestError\";\n }\n}\n\n/**\n * The stateless request shell the endpoints share: body-shape validation,\n * the notification 202, missing-method rejection, and error mapping.\n * `dispatch` returns the JSON-RPC result for a method; it throws\n * {@link McpRequestError} for coded failures (-32601 method-not-found,\n * -32602 bad params) and anything else becomes -32603.\n */\nexport async function handleMcpPost(\n reply: FastifyReply,\n body: unknown,\n dispatch: (\n method: string,\n params: Record<string, unknown>,\n ) => Promise<unknown>,\n): Promise<FastifyReply> {\n const message = body as JsonRpcMessage | null;\n if (!message || typeof message !== \"object\" || Array.isArray(message)) {\n return rpcError(reply, null, -32600, \"Expected a single JSON-RPC message\");\n }\n // Notifications (initialized, cancelled, …) need no body in return.\n if (message.id === undefined || message.id === null) {\n return reply.status(202).send();\n }\n if (typeof message.method !== \"string\") {\n return rpcError(reply, message.id, -32600, \"Missing method\");\n }\n try {\n const result = await dispatch(message.method, message.params ?? {});\n return rpcResult(reply, message.id, result);\n } catch (error) {\n if (error instanceof McpRequestError) {\n return rpcError(reply, message.id, error.code, error.message);\n }\n return rpcError(\n reply,\n message.id,\n -32603,\n error instanceof Error ? error.message : \"Internal error\",\n );\n }\n}\n\nexport function rpcResult(\n reply: FastifyReply,\n id: number | string,\n result: unknown,\n): FastifyReply {\n return reply\n .header(\"content-type\", \"application/json\")\n .send({ jsonrpc: \"2.0\", id, result });\n}\n\nexport function rpcError(\n reply: FastifyReply,\n id: number | string | null,\n code: number,\n message: string,\n): FastifyReply {\n return reply\n .header(\"content-type\", \"application/json\")\n .send({ jsonrpc: \"2.0\", id, error: { code, message } });\n}\n\n/**\n * Tool result: JSON text for model readability plus `structuredContent`\n * for structured consumers. MCP defines structured content as a JSON\n * object, and clients such as Claude Code reject anything else, so arrays\n * and primitives ride the text channel alone.\n */\nexport function toolValue(value: unknown): Record<string, unknown> {\n return {\n content: [{ type: \"text\", text: JSON.stringify(value) ?? \"null\" }],\n ...(typeof value === \"object\" && value !== null && !Array.isArray(value)\n ? { structuredContent: value }\n : {}),\n };\n}\n\nexport function toolError(message: string): Record<string, unknown> {\n return { content: [{ type: \"text\", text: message }], isError: true };\n}\n\n/**\n * Another MCP server's tool, listed as that server declared it (ADR 0225).\n * These endpoints speak revisions where an output schema describes an\n * object, so any other is left out: advertising it would make clients\n * reject the results it describes.\n */\nexport function forwardedTool(tool: {\n name: string;\n title?: string;\n description?: string;\n inputSchema: unknown;\n outputSchema?: unknown;\n annotations?: unknown;\n}): Record<string, unknown> {\n return {\n name: tool.name,\n ...(tool.title ? { title: tool.title } : {}),\n ...(tool.description ? { description: tool.description } : {}),\n inputSchema: tool.inputSchema,\n ...(isObjectSchema(tool.outputSchema)\n ? { outputSchema: tool.outputSchema }\n : {}),\n ...(tool.annotations ? { annotations: tool.annotations } : {}),\n };\n}\n\nconst ForwardedToolResultSchema = z.looseObject({\n content: z.array(z.unknown()),\n structuredContent: z.unknown().optional(),\n});\n\n/**\n * Another MCP server's tool result, forwarded as it was sent: content,\n * structured content, `isError` and `_meta` unchanged (ADR 0225). These\n * revisions require structured content to be an object, so any other\n * (which newer revisions allow) is left out, and becomes the text when the\n * server sent none. Anything that is not a tool result answers as a value,\n * never as a failure: the call has already run.\n */\nexport function forwardedToolResult(result: unknown): Record<string, unknown> {\n const parsed = ForwardedToolResultSchema.safeParse(result);\n if (!parsed.success) return toolValue(result);\n const { structuredContent, ...rest } = parsed.data;\n if (structuredContent === undefined) return rest;\n if (isObject(structuredContent)) return { ...rest, structuredContent };\n return rest.content.length > 0\n ? rest\n : {\n ...rest,\n content: [{ type: \"text\", text: JSON.stringify(structuredContent) }],\n };\n}\n\nfunction isObject(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction isObjectSchema(schema: unknown): boolean {\n return isObject(schema) && schema.type === \"object\";\n}\n\n/**\n * Shared contract with `@catamorphic/app`'s MCP-host guest adapter (which\n * duplicates the name — it cannot depend on core).\n */\nexport const POLL_RUN_TOOL = MCP_POLL_RUN_TOOL;\n\n/** The poll tool served beside the real tools on both MCP endpoints. */\nexport const POLL_RUN_TOOL_DEFINITION: Record<string, unknown> = {\n name: POLL_RUN_TOOL,\n annotations: { readOnlyHint: true },\n description:\n \"Poll a workflow run by its runId — one started asynchronously or one \" +\n \"that detached mid-call. Returns the run's status, output (once \" +\n \"completed), and batch progress.\",\n inputSchema: {\n type: \"object\",\n properties: { runId: { type: \"string\" } },\n required: [\"runId\"],\n },\n};\n\n/** The poll tool's shared implementation, same on both endpoints. */\nexport async function callPollRunTool(\n core: CatamorphicCore,\n identity: Identity,\n args: Record<string, unknown>,\n): Promise<Record<string, unknown>> {\n const runId = typeof args.runId === \"string\" ? args.runId : \"\";\n try {\n return toolValue(await fetchRunSnapshot(core, identity, runId));\n } catch (error) {\n if (error instanceof RunNotFoundError) return toolError(\"Run not found\");\n throw error;\n }\n}\n\nexport interface RunSnapshotShape {\n runId: string;\n status: string;\n output: unknown;\n error: string | null;\n progress?: {\n discovered: number;\n succeeded: number;\n failed: number;\n skipped: number;\n };\n}\n\n/** Mirrors the in-product broker's run snapshot (AppMount's shape). */\nexport async function fetchRunSnapshot(\n core: CatamorphicCore,\n identity: Identity,\n runId: string,\n): Promise<RunSnapshotShape> {\n const run = await core.runs.get({ identity, runId });\n const batch = (\n run as {\n batchScopes?: Array<{\n discovered: number;\n succeeded: number;\n failed: number;\n skipped: number;\n }>;\n }\n ).batchScopes?.[0];\n return {\n runId: run.id,\n status: run.status,\n output: (run as { result?: unknown }).result ?? null,\n error: (run as { error?: string | null }).error ?? null,\n ...(batch\n ? {\n progress: {\n discovered: batch.discovered,\n succeeded: batch.succeeded,\n failed: batch.failed,\n skipped: batch.skipped,\n },\n }\n : {}),\n };\n}\n\n/** A tool another MCP server declared, as a forwarding endpoint lists it. */\nexport interface ForwardedToolDefinition {\n name: string;\n title?: string;\n description?: string;\n inputSchema: unknown;\n outputSchema?: unknown;\n annotations?: unknown;\n}\n\nconst CallParamsSchema = z.object({\n name: z.string().min(1),\n arguments: z.record(z.string(), z.unknown()).default({}),\n});\n\n/**\n * A stateless MCP endpoint serving another server's tools: tools listed\n * and results returned as that server declared and sent them (ADR 0225).\n * `callTool` answers with the server's own result (any tool result, such\n * as {@link toolError}, passes through), or throws {@link McpRequestError}\n * for a refusal at the protocol boundary.\n */\nexport function serveForwardedTools(args: {\n reply: FastifyReply;\n body: unknown;\n serverName: string;\n listTools(): Promise<readonly ForwardedToolDefinition[]>;\n callTool(call: {\n name: string;\n arguments: Record<string, unknown>;\n }): Promise<unknown>;\n}): Promise<FastifyReply> {\n return handleMcpPost(args.reply, args.body, async (method, params) => {\n switch (method) {\n case \"initialize\":\n return {\n protocolVersion: negotiateProtocolVersion(params.protocolVersion),\n capabilities: { tools: {} },\n serverInfo: { name: args.serverName, version: \"1\" },\n };\n case \"ping\":\n return {};\n case \"tools/list\":\n return { tools: (await args.listTools()).map(forwardedTool) };\n case \"tools/call\": {\n const call = CallParamsSchema.safeParse(params);\n if (!call.success)\n throw new McpRequestError(-32602, \"Invalid tool call\");\n return forwardedToolResult(await args.callTool(call.data));\n }\n default:\n throw new McpRequestError(-32601, \"Method not found\");\n }\n });\n}\n"
6
+ ],
7
+ "mappings": ";AACA;AAEA;AAmBO,IAAM,8BAA8B,IAAI,IAAI;AAAA,EACjD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AACM,IAAM,2BAA2B;AAGjC,SAAS,wBAAwB,CAAC,WAA4B;AAAA,EACnE,OAAO,OAAO,cAAc,YAC1B,4BAA4B,IAAI,SAAS,IACvC,YACA;AAAA;AAAA;AAIC,MAAM,yBAAwB,MAAM;AAAA,EAE9B;AAAA,EADX,WAAW,CACA,MACT,SACA;AAAA,IACA,MAAM,OAAO;AAAA,IAHJ;AAAA,IAIT,KAAK,OAAO;AAAA;AAEhB;AASO,eAAe,aAAa,CACjC,OACA,MACA,UAIuB;AAAA,EACvB,MAAM,UAAU;AAAA,EAChB,IAAI,CAAC,WAAW,OAAO,YAAY,YAAY,MAAM,QAAQ,OAAO,GAAG;AAAA,IACrE,OAAO,SAAS,OAAO,MAAM,QAAQ,oCAAoC;AAAA,EAC3E;AAAA,EAEA,IAAI,QAAQ,OAAO,aAAa,QAAQ,OAAO,MAAM;AAAA,IACnD,OAAO,MAAM,OAAO,GAAG,EAAE,KAAK;AAAA,EAChC;AAAA,EACA,IAAI,OAAO,QAAQ,WAAW,UAAU;AAAA,IACtC,OAAO,SAAS,OAAO,QAAQ,IAAI,QAAQ,gBAAgB;AAAA,EAC7D;AAAA,EACA,IAAI;AAAA,IACF,MAAM,SAAS,MAAM,SAAS,QAAQ,QAAQ,QAAQ,UAAU,CAAC,CAAC;AAAA,IAClE,OAAO,UAAU,OAAO,QAAQ,IAAI,MAAM;AAAA,IAC1C,OAAO,OAAO;AAAA,IACd,IAAI,iBAAiB,kBAAiB;AAAA,MACpC,OAAO,SAAS,OAAO,QAAQ,IAAI,MAAM,MAAM,MAAM,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