@frontmcp/sdk 0.1.0

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 (353) hide show
  1. package/README.md +11 -0
  2. package/package.json +29 -0
  3. package/src/constants.d.ts +30 -0
  4. package/src/constants.js +36 -0
  5. package/src/constants.js.map +1 -0
  6. package/src/decorators/adapter.decorator.d.ts +7 -0
  7. package/src/decorators/adapter.decorator.js +20 -0
  8. package/src/decorators/adapter.decorator.js.map +1 -0
  9. package/src/decorators/app.decorator.d.ts +7 -0
  10. package/src/decorators/app.decorator.js +44 -0
  11. package/src/decorators/app.decorator.js.map +1 -0
  12. package/src/decorators/auth-provider.decorator.d.ts +7 -0
  13. package/src/decorators/auth-provider.decorator.js +20 -0
  14. package/src/decorators/auth-provider.decorator.js.map +1 -0
  15. package/src/decorators/flow-hooks.decorator.d.ts +12 -0
  16. package/src/decorators/flow-hooks.decorator.js +63 -0
  17. package/src/decorators/flow-hooks.decorator.js.map +1 -0
  18. package/src/decorators/flow.decorator.d.ts +6 -0
  19. package/src/decorators/flow.decorator.js +19 -0
  20. package/src/decorators/flow.decorator.js.map +1 -0
  21. package/src/decorators/front-mcp.decorator.d.ts +6 -0
  22. package/src/decorators/front-mcp.decorator.js +40 -0
  23. package/src/decorators/front-mcp.decorator.js.map +1 -0
  24. package/src/decorators/index.d.ts +12 -0
  25. package/src/decorators/index.js +16 -0
  26. package/src/decorators/index.js.map +1 -0
  27. package/src/decorators/logger.decorator.d.ts +7 -0
  28. package/src/decorators/logger.decorator.js +20 -0
  29. package/src/decorators/logger.decorator.js.map +1 -0
  30. package/src/decorators/plugin.decorator.d.ts +7 -0
  31. package/src/decorators/plugin.decorator.js +38 -0
  32. package/src/decorators/plugin.decorator.js.map +1 -0
  33. package/src/decorators/prompt.decorator.d.ts +13 -0
  34. package/src/decorators/prompt.decorator.js +38 -0
  35. package/src/decorators/prompt.decorator.js.map +1 -0
  36. package/src/decorators/provider.decorator.d.ts +7 -0
  37. package/src/decorators/provider.decorator.js +20 -0
  38. package/src/decorators/provider.decorator.js.map +1 -0
  39. package/src/decorators/resource.decorator.d.ts +17 -0
  40. package/src/decorators/resource.decorator.js +52 -0
  41. package/src/decorators/resource.decorator.js.map +1 -0
  42. package/src/decorators/tool.decorator.d.ts +14 -0
  43. package/src/decorators/tool.decorator.js +38 -0
  44. package/src/decorators/tool.decorator.js.map +1 -0
  45. package/src/decorators-old/async-with.decorator.d.ts +9 -0
  46. package/src/decorators-old/async-with.decorator.js +23 -0
  47. package/src/decorators-old/async-with.decorator.js.map +1 -0
  48. package/src/decorators-old/auth-hook.decorator.d.ts +14 -0
  49. package/src/decorators-old/auth-hook.decorator.js +27 -0
  50. package/src/decorators-old/auth-hook.decorator.js.map +1 -0
  51. package/src/decorators-old/session-hook.decorator.d.ts +14 -0
  52. package/src/decorators-old/session-hook.decorator.js +27 -0
  53. package/src/decorators-old/session-hook.decorator.js.map +1 -0
  54. package/src/decorators-old/tool-hook.decorator.d.ts +14 -0
  55. package/src/decorators-old/tool-hook.decorator.js +27 -0
  56. package/src/decorators-old/tool-hook.decorator.js.map +1 -0
  57. package/src/dynamic/dynamic.adapter.d.ts +42 -0
  58. package/src/dynamic/dynamic.adapter.js +28 -0
  59. package/src/dynamic/dynamic.adapter.js.map +1 -0
  60. package/src/dynamic/dynamic.plugin.d.ts +52 -0
  61. package/src/dynamic/dynamic.plugin.js +33 -0
  62. package/src/dynamic/dynamic.plugin.js.map +1 -0
  63. package/src/dynamic/dynamic.utils.d.ts +3 -0
  64. package/src/dynamic/dynamic.utils.js +27 -0
  65. package/src/dynamic/dynamic.utils.js.map +1 -0
  66. package/src/dynamic/index.d.ts +2 -0
  67. package/src/dynamic/index.js +6 -0
  68. package/src/dynamic/index.js.map +1 -0
  69. package/src/entries/adapter.entry.d.ts +6 -0
  70. package/src/entries/adapter.entry.js +8 -0
  71. package/src/entries/adapter.entry.js.map +1 -0
  72. package/src/entries/app.entry.d.ts +13 -0
  73. package/src/entries/app.entry.js +9 -0
  74. package/src/entries/app.entry.js.map +1 -0
  75. package/src/entries/auth-provider.entry.d.ts +6 -0
  76. package/src/entries/auth-provider.entry.js +8 -0
  77. package/src/entries/auth-provider.entry.js.map +1 -0
  78. package/src/entries/base.entry.d.ts +20 -0
  79. package/src/entries/base.entry.js +17 -0
  80. package/src/entries/base.entry.js.map +1 -0
  81. package/src/entries/flow.entry.d.ts +15 -0
  82. package/src/entries/flow.entry.js +21 -0
  83. package/src/entries/flow.entry.js.map +1 -0
  84. package/src/entries/index.d.ts +12 -0
  85. package/src/entries/index.js +16 -0
  86. package/src/entries/index.js.map +1 -0
  87. package/src/entries/logger.entry.d.ts +6 -0
  88. package/src/entries/logger.entry.js +8 -0
  89. package/src/entries/logger.entry.js.map +1 -0
  90. package/src/entries/plugin.entry.d.ts +6 -0
  91. package/src/entries/plugin.entry.js +8 -0
  92. package/src/entries/plugin.entry.js.map +1 -0
  93. package/src/entries/prompt.entry.d.ts +6 -0
  94. package/src/entries/prompt.entry.js +8 -0
  95. package/src/entries/prompt.entry.js.map +1 -0
  96. package/src/entries/provider.entry.d.ts +7 -0
  97. package/src/entries/provider.entry.js +8 -0
  98. package/src/entries/provider.entry.js.map +1 -0
  99. package/src/entries/resource.entry.d.ts +7 -0
  100. package/src/entries/resource.entry.js +11 -0
  101. package/src/entries/resource.entry.js.map +1 -0
  102. package/src/entries/scope.entry.d.ts +17 -0
  103. package/src/entries/scope.entry.js +8 -0
  104. package/src/entries/scope.entry.js.map +1 -0
  105. package/src/entries/tool.entry.d.ts +15 -0
  106. package/src/entries/tool.entry.js +11 -0
  107. package/src/entries/tool.entry.js.map +1 -0
  108. package/src/index.d.ts +18 -0
  109. package/src/index.js +22 -0
  110. package/src/index.js.map +1 -0
  111. package/src/interfaces/adapter.interface.d.ts +20 -0
  112. package/src/interfaces/adapter.interface.js +3 -0
  113. package/src/interfaces/adapter.interface.js.map +1 -0
  114. package/src/interfaces/app.interface.d.ts +6 -0
  115. package/src/interfaces/app.interface.js +3 -0
  116. package/src/interfaces/app.interface.js.map +1 -0
  117. package/src/interfaces/auth-hook.interface.d.ts +126 -0
  118. package/src/interfaces/auth-hook.interface.js +135 -0
  119. package/src/interfaces/auth-hook.interface.js.map +1 -0
  120. package/src/interfaces/auth-provider.interface.d.ts +22 -0
  121. package/src/interfaces/auth-provider.interface.js +18 -0
  122. package/src/interfaces/auth-provider.interface.js.map +1 -0
  123. package/src/interfaces/base.interface.d.ts +77 -0
  124. package/src/interfaces/base.interface.js +3 -0
  125. package/src/interfaces/base.interface.js.map +1 -0
  126. package/src/interfaces/flow.interface.d.ts +38 -0
  127. package/src/interfaces/flow.interface.js +69 -0
  128. package/src/interfaces/flow.interface.js.map +1 -0
  129. package/src/interfaces/front-mcp.interface.d.ts +5 -0
  130. package/src/interfaces/front-mcp.interface.js +3 -0
  131. package/src/interfaces/front-mcp.interface.js.map +1 -0
  132. package/src/interfaces/index.d.ts +15 -0
  133. package/src/interfaces/index.js +19 -0
  134. package/src/interfaces/index.js.map +1 -0
  135. package/src/interfaces/internal/flow.utils.d.ts +24 -0
  136. package/src/interfaces/internal/flow.utils.js +83 -0
  137. package/src/interfaces/internal/flow.utils.js.map +1 -0
  138. package/src/interfaces/internal/index.d.ts +2 -0
  139. package/src/interfaces/internal/index.js +7 -0
  140. package/src/interfaces/internal/index.js.map +1 -0
  141. package/src/interfaces/internal/primary-auth-provider.interface.d.ts +24 -0
  142. package/src/interfaces/internal/primary-auth-provider.interface.js +33 -0
  143. package/src/interfaces/internal/primary-auth-provider.interface.js.map +1 -0
  144. package/src/interfaces/internal/registry.interface.d.ts +71 -0
  145. package/src/interfaces/internal/registry.interface.js +3 -0
  146. package/src/interfaces/internal/registry.interface.js.map +1 -0
  147. package/src/interfaces/logger.interface.d.ts +42 -0
  148. package/src/interfaces/logger.interface.js +10 -0
  149. package/src/interfaces/logger.interface.js.map +1 -0
  150. package/src/interfaces/plugin.interface.d.ts +8 -0
  151. package/src/interfaces/plugin.interface.js +3 -0
  152. package/src/interfaces/plugin.interface.js.map +1 -0
  153. package/src/interfaces/prompt.interface.d.ts +5 -0
  154. package/src/interfaces/prompt.interface.js +3 -0
  155. package/src/interfaces/prompt.interface.js.map +1 -0
  156. package/src/interfaces/provider.interface.d.ts +20 -0
  157. package/src/interfaces/provider.interface.js +18 -0
  158. package/src/interfaces/provider.interface.js.map +1 -0
  159. package/src/interfaces/resource.interface.d.ts +21 -0
  160. package/src/interfaces/resource.interface.js +3 -0
  161. package/src/interfaces/resource.interface.js.map +1 -0
  162. package/src/interfaces/scope.interface.d.ts +5 -0
  163. package/src/interfaces/scope.interface.js +3 -0
  164. package/src/interfaces/scope.interface.js.map +1 -0
  165. package/src/interfaces/server.interface.d.ts +46 -0
  166. package/src/interfaces/server.interface.js +18 -0
  167. package/src/interfaces/server.interface.js.map +1 -0
  168. package/src/interfaces/session-hook.interface.d.ts +131 -0
  169. package/src/interfaces/session-hook.interface.js +140 -0
  170. package/src/interfaces/session-hook.interface.js.map +1 -0
  171. package/src/interfaces/tool-hook.interface.d.ts +80 -0
  172. package/src/interfaces/tool-hook.interface.js +92 -0
  173. package/src/interfaces/tool-hook.interface.js.map +1 -0
  174. package/src/interfaces/tool.interface.d.ts +45 -0
  175. package/src/interfaces/tool.interface.js +89 -0
  176. package/src/interfaces/tool.interface.js.map +1 -0
  177. package/src/metadata/adapter.metadata.d.ts +22 -0
  178. package/src/metadata/adapter.metadata.js +10 -0
  179. package/src/metadata/adapter.metadata.js.map +1 -0
  180. package/src/metadata/app.metadata.d.ts +872 -0
  181. package/src/metadata/app.metadata.js +30 -0
  182. package/src/metadata/app.metadata.js.map +1 -0
  183. package/src/metadata/auth-provider.metadata.d.ts +33 -0
  184. package/src/metadata/auth-provider.metadata.js +19 -0
  185. package/src/metadata/auth-provider.metadata.js.map +1 -0
  186. package/src/metadata/flow-hooks.metadata.d.ts +20 -0
  187. package/src/metadata/flow-hooks.metadata.js +3 -0
  188. package/src/metadata/flow-hooks.metadata.js.map +1 -0
  189. package/src/metadata/flow.metadata.d.ts +75 -0
  190. package/src/metadata/flow.metadata.js +15 -0
  191. package/src/metadata/flow.metadata.js.map +1 -0
  192. package/src/metadata/front-mcp.metadata.d.ts +1144 -0
  193. package/src/metadata/front-mcp.metadata.js +25 -0
  194. package/src/metadata/front-mcp.metadata.js.map +1 -0
  195. package/src/metadata/index.d.ts +12 -0
  196. package/src/metadata/index.js +16 -0
  197. package/src/metadata/index.js.map +1 -0
  198. package/src/metadata/logger.metadata.d.ts +39 -0
  199. package/src/metadata/logger.metadata.js +10 -0
  200. package/src/metadata/logger.metadata.js.map +1 -0
  201. package/src/metadata/plugin.metadata.d.ts +93 -0
  202. package/src/metadata/plugin.metadata.js +18 -0
  203. package/src/metadata/plugin.metadata.js.map +1 -0
  204. package/src/metadata/prompt.metadata.d.ts +226 -0
  205. package/src/metadata/prompt.metadata.js +27 -0
  206. package/src/metadata/prompt.metadata.js.map +1 -0
  207. package/src/metadata/provider.metadata.d.ts +34 -0
  208. package/src/metadata/provider.metadata.js +20 -0
  209. package/src/metadata/provider.metadata.js.map +1 -0
  210. package/src/metadata/resource.metadata.d.ts +199 -0
  211. package/src/metadata/resource.metadata.js +22 -0
  212. package/src/metadata/resource.metadata.js.map +1 -0
  213. package/src/metadata/tool.metadata.d.ts +278 -0
  214. package/src/metadata/tool.metadata.js +28 -0
  215. package/src/metadata/tool.metadata.js.map +1 -0
  216. package/src/providers/session.provider.d.ts +13 -0
  217. package/src/providers/session.provider.js +27 -0
  218. package/src/providers/session.provider.js.map +1 -0
  219. package/src/records/adapter.record.d.ts +26 -0
  220. package/src/records/adapter.record.js +11 -0
  221. package/src/records/adapter.record.js.map +1 -0
  222. package/src/records/app.record.d.ts +19 -0
  223. package/src/records/app.record.js +9 -0
  224. package/src/records/app.record.js.map +1 -0
  225. package/src/records/auth-provider.record.d.ts +37 -0
  226. package/src/records/auth-provider.record.js +12 -0
  227. package/src/records/auth-provider.record.js.map +1 -0
  228. package/src/records/flow.record.d.ts +11 -0
  229. package/src/records/flow.record.js +8 -0
  230. package/src/records/flow.record.js.map +1 -0
  231. package/src/records/index.d.ts +11 -0
  232. package/src/records/index.js +15 -0
  233. package/src/records/index.js.map +1 -0
  234. package/src/records/logger.record.d.ts +11 -0
  235. package/src/records/logger.record.js +8 -0
  236. package/src/records/logger.record.js.map +1 -0
  237. package/src/records/plugin.record.d.ts +21 -0
  238. package/src/records/plugin.record.js +11 -0
  239. package/src/records/plugin.record.js.map +1 -0
  240. package/src/records/prompt.record.d.ts +18 -0
  241. package/src/records/prompt.record.js +9 -0
  242. package/src/records/prompt.record.js.map +1 -0
  243. package/src/records/provider.record.d.ts +36 -0
  244. package/src/records/provider.record.js +14 -0
  245. package/src/records/provider.record.js.map +1 -0
  246. package/src/records/resource.record.d.ts +18 -0
  247. package/src/records/resource.record.js +14 -0
  248. package/src/records/resource.record.js.map +1 -0
  249. package/src/records/scope.record.d.ts +18 -0
  250. package/src/records/scope.record.js +9 -0
  251. package/src/records/scope.record.js.map +1 -0
  252. package/src/records/tool.record.d.ts +17 -0
  253. package/src/records/tool.record.js +9 -0
  254. package/src/records/tool.record.js.map +1 -0
  255. package/src/schemas/annotated-class.schema.d.ts +11 -0
  256. package/src/schemas/annotated-class.schema.js +40 -0
  257. package/src/schemas/annotated-class.schema.js.map +1 -0
  258. package/src/schemas/http-input.schema.d.ts +33 -0
  259. package/src/schemas/http-input.schema.js +13 -0
  260. package/src/schemas/http-input.schema.js.map +1 -0
  261. package/src/schemas/http-output.schema.d.ts +2011 -0
  262. package/src/schemas/http-output.schema.js +283 -0
  263. package/src/schemas/http-output.schema.js.map +1 -0
  264. package/src/schemas/index.d.ts +3 -0
  265. package/src/schemas/index.js +7 -0
  266. package/src/schemas/index.js.map +1 -0
  267. package/src/tokens/adapter.tokens.d.ts +3 -0
  268. package/src/tokens/adapter.tokens.js +11 -0
  269. package/src/tokens/adapter.tokens.js.map +1 -0
  270. package/src/tokens/app.tokens.d.ts +4 -0
  271. package/src/tokens/app.tokens.js +30 -0
  272. package/src/tokens/app.tokens.js.map +1 -0
  273. package/src/tokens/auth-provider.tokens.d.ts +3 -0
  274. package/src/tokens/auth-provider.tokens.js +12 -0
  275. package/src/tokens/auth-provider.tokens.js.map +1 -0
  276. package/src/tokens/base.tokens.d.ts +5 -0
  277. package/src/tokens/base.tokens.js +9 -0
  278. package/src/tokens/base.tokens.js.map +1 -0
  279. package/src/tokens/flow-hook.tokens.d.ts +4 -0
  280. package/src/tokens/flow-hook.tokens.js +9 -0
  281. package/src/tokens/flow-hook.tokens.js.map +1 -0
  282. package/src/tokens/flow.tokens.d.ts +11 -0
  283. package/src/tokens/flow.tokens.js +16 -0
  284. package/src/tokens/flow.tokens.js.map +1 -0
  285. package/src/tokens/front-mcp.tokens.d.ts +3 -0
  286. package/src/tokens/front-mcp.tokens.js +19 -0
  287. package/src/tokens/front-mcp.tokens.js.map +1 -0
  288. package/src/tokens/index.d.ts +13 -0
  289. package/src/tokens/index.js +17 -0
  290. package/src/tokens/index.js.map +1 -0
  291. package/src/tokens/logger.tokens.d.ts +3 -0
  292. package/src/tokens/logger.tokens.js +11 -0
  293. package/src/tokens/logger.tokens.js.map +1 -0
  294. package/src/tokens/plugin.tokens.d.ts +13 -0
  295. package/src/tokens/plugin.tokens.js +18 -0
  296. package/src/tokens/plugin.tokens.js.map +1 -0
  297. package/src/tokens/prompt.tokens.d.ts +9 -0
  298. package/src/tokens/prompt.tokens.js +14 -0
  299. package/src/tokens/prompt.tokens.js.map +1 -0
  300. package/src/tokens/provider.tokens.d.ts +3 -0
  301. package/src/tokens/provider.tokens.js +12 -0
  302. package/src/tokens/provider.tokens.js.map +1 -0
  303. package/src/tokens/resource.tokens.d.ts +20 -0
  304. package/src/tokens/resource.tokens.js +25 -0
  305. package/src/tokens/resource.tokens.js.map +1 -0
  306. package/src/tokens/server.tokens.d.ts +6 -0
  307. package/src/tokens/server.tokens.js +11 -0
  308. package/src/tokens/server.tokens.js.map +1 -0
  309. package/src/tokens/tool.tokens.d.ts +13 -0
  310. package/src/tokens/tool.tokens.js +18 -0
  311. package/src/tokens/tool.tokens.js.map +1 -0
  312. package/src/types/auth/index.d.ts +2 -0
  313. package/src/types/auth/index.js +6 -0
  314. package/src/types/auth/index.js.map +1 -0
  315. package/src/types/auth/jwt.types.d.ts +112 -0
  316. package/src/types/auth/jwt.types.js +36 -0
  317. package/src/types/auth/jwt.types.js.map +1 -0
  318. package/src/types/auth/session.types.d.ts +263 -0
  319. package/src/types/auth/session.types.js +40 -0
  320. package/src/types/auth/session.types.js.map +1 -0
  321. package/src/types/common.types.d.ts +11 -0
  322. package/src/types/common.types.js +3 -0
  323. package/src/types/common.types.js.map +1 -0
  324. package/src/types/index.d.ts +3 -0
  325. package/src/types/index.js +7 -0
  326. package/src/types/index.js.map +1 -0
  327. package/src/types/options/auth.options.d.ts +513 -0
  328. package/src/types/options/auth.options.js +53 -0
  329. package/src/types/options/auth.options.js.map +1 -0
  330. package/src/types/options/http.options.d.ts +22 -0
  331. package/src/types/options/http.options.js +10 -0
  332. package/src/types/options/http.options.js.map +1 -0
  333. package/src/types/options/index.d.ts +5 -0
  334. package/src/types/options/index.js +9 -0
  335. package/src/types/options/index.js.map +1 -0
  336. package/src/types/options/logging.options.d.ts +39 -0
  337. package/src/types/options/logging.options.js +37 -0
  338. package/src/types/options/logging.options.js.map +1 -0
  339. package/src/types/options/server-info.options.d.ts +48 -0
  340. package/src/types/options/server-info.options.js +13 -0
  341. package/src/types/options/server-info.options.js.map +1 -0
  342. package/src/types/options/session.options.d.ts +67 -0
  343. package/src/types/options/session.options.js +9 -0
  344. package/src/types/options/session.options.js.map +1 -0
  345. package/src/utils/decide-request-intent.utils.d.ts +79 -0
  346. package/src/utils/decide-request-intent.utils.js +326 -0
  347. package/src/utils/decide-request-intent.utils.js.map +1 -0
  348. package/src/utils/index.d.ts +2 -0
  349. package/src/utils/index.js +6 -0
  350. package/src/utils/index.js.map +1 -0
  351. package/src/utils/path.utils.d.ts +20 -0
  352. package/src/utils/path.utils.js +66 -0
  353. package/src/utils/path.utils.js.map +1 -0
@@ -0,0 +1,140 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SessionHookStage = void 0;
4
+ /**
5
+ * Lifecycle stages for session invocation.
6
+ *
7
+ * Ordering notes:
8
+ * - "will*" stages run before the action; "did*" stages run after.
9
+ * - Higher `priority()` runs earlier for "will*" (outermost), and later for "did*".
10
+ * - Finalization stages (`willFinalize`, `willAudit`, `didAudit`, `onMetrics`) should be placed
11
+ * in your plan’s `finalize` array to run on both success and error paths.
12
+ *
13
+ * Control flow:
14
+ * - Hooks may call `ctx.respond(value)` to short-circuit with a return value.
15
+ * - Hooks may call `ctx.abort(reason, code?, httpStatus?)` to stop with an error.
16
+ *
17
+ * Common context fields:
18
+ * - `ctx.sessionId` SecureMcp session id (== secureJwt) once created/validated.
19
+ * - `ctx.input`/`output` Arbitrary payloads for the current flow.
20
+ * - `ctx.data` Shared bag for cross-hook state.
21
+ * - `ctx.providers` Optional provider views if needed for UI/selection.
22
+ */
23
+ var SessionHookStage;
24
+ (function (SessionHookStage) {
25
+ /** Prepare a new session (or re-register an incoming secureJwt).
26
+ * Responsibilities:
27
+ * - Validate incoming token (if any); compute defaults; attach user hints.
28
+ * - Initialize per-session resources and attach to `ctx.data`.
29
+ * Failure modes:
30
+ * - `ctx.abort('invalid jwt', 'INVALID_SESSION', 401)`.
31
+ */
32
+ SessionHookStage["willCreateSession"] = "willCreateSession";
33
+ /** Session created and registered.
34
+ * Responsibilities:
35
+ * - Announce readiness (mount handlers/streams), emit side-effects if needed.
36
+ * - Optionally shape `ctx.output` with a `SessionContextView`.
37
+ */
38
+ SessionHookStage["didCreateSession"] = "didCreateSession";
39
+ /** Bind DI providers needed for this session/request.
40
+ * Responsibilities:
41
+ * - Resolve and bind providers so later hooks can `ctx.get(...)`.
42
+ * - May set `ctx.bindProvider/bindProviders` helpers.
43
+ */
44
+ SessionHookStage["willBindProviders"] = "willBindProviders";
45
+ // ---------- Auth (within a session) ----------
46
+ /** Signal the beginning of an auth sequence in the scope of this session.
47
+ * Responsibilities:
48
+ * - Initialize auth-related state (PKCE/state, CSRF, telemetry).
49
+ * - Decide transport (SSE/StreamableHTTP) for status/URL events if applicable.
50
+ */
51
+ SessionHookStage["willBeginAuth"] = "willBeginAuth";
52
+ /** Streamable authorization progress within the session.
53
+ * Responsibilities:
54
+ * - Emit URL/status events (e.g., “authorize_url”, “awaiting_callback”).
55
+ * - Optionally `ctx.respond({event: ...})` for push-style transports.
56
+ */
57
+ SessionHookStage["willAuthorize"] = "willAuthorize";
58
+ /** Prepare and gate the token exchange with the provider.
59
+ * Responsibilities:
60
+ * - Verify callback params; ensure prerequisites (sessionId present).
61
+ * - Compute exchange request; rate-limit/anti-replay checks.
62
+ * Failure modes:
63
+ * - `ctx.abort('invalid state/pkce', 'OAUTH_CALLBACK_ERROR', 400)`.
64
+ */
65
+ SessionHookStage["willExchangeToken"] = "willExchangeToken";
66
+ /** SecureMcp JWT has been minted/confirmed for this session.
67
+ * Responsibilities:
68
+ * - React to issuance (e.g., persist session claims, notify listeners).
69
+ * Notes:
70
+ * - Fired once the session’s secureJwt is known; avoid logging secrets.
71
+ */
72
+ SessionHookStage["didIssueSecureJwt"] = "didIssueSecureJwt";
73
+ /** Encrypt and store provider tokens for this session.
74
+ * Responsibilities:
75
+ * - Write encrypted blobs to the session record (per provider).
76
+ * - Derive minimal metadata (scopes/expiry) for later claims-only exposure.
77
+ */
78
+ SessionHookStage["willStoreTokens"] = "willStoreTokens";
79
+ // ---------- Access (read path) ----------
80
+ /** Authorize and prepare a session read.
81
+ * Responsibilities:
82
+ * - Validate access to the session; attach read-scoped providers if required.
83
+ * - Optionally shape a partial view before execute.
84
+ */
85
+ SessionHookStage["willGetSession"] = "willGetSession";
86
+ /** Post-process the session view.
87
+ * Responsibilities:
88
+ * - Redact/transform/derive fields for the final response.
89
+ * - Set `ctx.output` to a `SessionContextView`.
90
+ */
91
+ SessionHookStage["didGetSession"] = "didGetSession";
92
+ // ---------- Disposal ----------
93
+ /** Announce shutdown and allow flush/cleanup.
94
+ * Responsibilities:
95
+ * - Close streams, unsubscribe listeners, schedule disposers.
96
+ */
97
+ SessionHookStage["willDisposeSession"] = "willDisposeSession";
98
+ /** Confirm teardown and emit metrics.
99
+ * Responsibilities:
100
+ * - Final confirmation of resource release; summarize outcome.
101
+ */
102
+ SessionHookStage["didDisposeSession"] = "didDisposeSession";
103
+ // ---------- Finalize / audit / metrics / errors ----------
104
+ /** Optional “late finally” hook if you need a single place before audit/metrics.
105
+ * Responsibilities:
106
+ * - Last-chance cleanup across success/error paths (idempotent, non-throwing).
107
+ * Notes:
108
+ * - Include this stage in your plan’s `finalize` array to activate.
109
+ */
110
+ SessionHookStage["willFinalize"] = "willFinalize";
111
+ /** Centralized error handler.
112
+ * Responsibilities:
113
+ * - Redact sensitive data; map internal errors to public codes.
114
+ * - Optionally `ctx.respond({ error })` or `ctx.abort(...)`.
115
+ * Notes:
116
+ * - Should not throw; runs before audit/metrics finalize.
117
+ */
118
+ SessionHookStage["onError"] = "onError";
119
+ /** Pre-audit collection on both success and error paths.
120
+ * Responsibilities:
121
+ * - Build audit envelope (actor, sessionId, providers touched).
122
+ * - Normalize and strip secrets (no raw tokens).
123
+ */
124
+ SessionHookStage["willAudit"] = "willAudit";
125
+ /** Persist/emit the audit record.
126
+ * Responsibilities:
127
+ * - Write to audit sink(s) with outcome and timings.
128
+ * - Correlate via `ctx.requestId`/`ctx.sessionId`.
129
+ */
130
+ SessionHookStage["didAudit"] = "didAudit";
131
+ /** Telemetry/metrics emission for both success and errors.
132
+ * Responsibilities:
133
+ * - Counters & timings (create/get/dispose/auth/exchange/store).
134
+ * - Error code/tag cardinality kept small for SLOs/alerts.
135
+ * Constraints:
136
+ * - Non-throwing; must not alter control flow.
137
+ */
138
+ SessionHookStage["onMetrics"] = "onMetrics";
139
+ })(SessionHookStage || (exports.SessionHookStage = SessionHookStage = {}));
140
+ //# sourceMappingURL=session-hook.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session-hook.interface.js","sourceRoot":"","sources":["../../../src/interfaces/session-hook.interface.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,IAAY,gBAuIX;AAvID,WAAY,gBAAgB;IAC1B;;;;;;OAMG;IACH,2DAAuC,CAAA;IAEvC;;;;OAIG;IACH,yDAAqC,CAAA;IAErC;;;;OAIG;IACH,2DAAuC,CAAA;IAEvC,gDAAgD;IAEhD;;;;OAIG;IACH,mDAA+B,CAAA;IAE/B;;;;OAIG;IACH,mDAA+B,CAAA;IAE/B;;;;;;OAMG;IACH,2DAAuC,CAAA;IAEvC;;;;;OAKG;IACH,2DAAuC,CAAA;IAEvC;;;;OAIG;IACH,uDAAmC,CAAA;IAEnC,2CAA2C;IAE3C;;;;OAIG;IACH,qDAAiC,CAAA;IAEjC;;;;OAIG;IACH,mDAA+B,CAAA;IAE/B,iCAAiC;IAEjC;;;OAGG;IACH,6DAAyC,CAAA;IAEzC;;;OAGG;IACH,2DAAuC,CAAA;IAEvC,4DAA4D;IAE5D;;;;;OAKG;IACH,iDAA6B,CAAA;IAE7B;;;;;;OAMG;IACH,uCAAmB,CAAA;IAEnB;;;;OAIG;IACH,2CAAuB,CAAA;IAEvB;;;;OAIG;IACH,yCAAqB,CAAA;IAErB;;;;;;OAMG;IACH,2CAAuB,CAAA;AACzB,CAAC,EAvIW,gBAAgB,gCAAhB,gBAAgB,QAuI3B","sourcesContent":["/**\n * Lifecycle stages for session invocation.\n *\n * Ordering notes:\n * - \"will*\" stages run before the action; \"did*\" stages run after.\n * - Higher `priority()` runs earlier for \"will*\" (outermost), and later for \"did*\".\n * - Finalization stages (`willFinalize`, `willAudit`, `didAudit`, `onMetrics`) should be placed\n * in your plan’s `finalize` array to run on both success and error paths.\n *\n * Control flow:\n * - Hooks may call `ctx.respond(value)` to short-circuit with a return value.\n * - Hooks may call `ctx.abort(reason, code?, httpStatus?)` to stop with an error.\n *\n * Common context fields:\n * - `ctx.sessionId` SecureMcp session id (== secureJwt) once created/validated.\n * - `ctx.input`/`output` Arbitrary payloads for the current flow.\n * - `ctx.data` Shared bag for cross-hook state.\n * - `ctx.providers` Optional provider views if needed for UI/selection.\n */\nexport enum SessionHookStage {\n /** Prepare a new session (or re-register an incoming secureJwt).\n * Responsibilities:\n * - Validate incoming token (if any); compute defaults; attach user hints.\n * - Initialize per-session resources and attach to `ctx.data`.\n * Failure modes:\n * - `ctx.abort('invalid jwt', 'INVALID_SESSION', 401)`.\n */\n willCreateSession = 'willCreateSession',\n\n /** Session created and registered.\n * Responsibilities:\n * - Announce readiness (mount handlers/streams), emit side-effects if needed.\n * - Optionally shape `ctx.output` with a `SessionContextView`.\n */\n didCreateSession = 'didCreateSession',\n\n /** Bind DI providers needed for this session/request.\n * Responsibilities:\n * - Resolve and bind providers so later hooks can `ctx.get(...)`.\n * - May set `ctx.bindProvider/bindProviders` helpers.\n */\n willBindProviders = 'willBindProviders',\n\n // ---------- Auth (within a session) ----------\n\n /** Signal the beginning of an auth sequence in the scope of this session.\n * Responsibilities:\n * - Initialize auth-related state (PKCE/state, CSRF, telemetry).\n * - Decide transport (SSE/StreamableHTTP) for status/URL events if applicable.\n */\n willBeginAuth = 'willBeginAuth',\n\n /** Streamable authorization progress within the session.\n * Responsibilities:\n * - Emit URL/status events (e.g., “authorize_url”, “awaiting_callback”).\n * - Optionally `ctx.respond({event: ...})` for push-style transports.\n */\n willAuthorize = 'willAuthorize', // stream-able events (URL/status)\n\n /** Prepare and gate the token exchange with the provider.\n * Responsibilities:\n * - Verify callback params; ensure prerequisites (sessionId present).\n * - Compute exchange request; rate-limit/anti-replay checks.\n * Failure modes:\n * - `ctx.abort('invalid state/pkce', 'OAUTH_CALLBACK_ERROR', 400)`.\n */\n willExchangeToken = 'willExchangeToken',\n\n /** SecureMcp JWT has been minted/confirmed for this session.\n * Responsibilities:\n * - React to issuance (e.g., persist session claims, notify listeners).\n * Notes:\n * - Fired once the session’s secureJwt is known; avoid logging secrets.\n */\n didIssueSecureJwt = 'didIssueSecureJwt',\n\n /** Encrypt and store provider tokens for this session.\n * Responsibilities:\n * - Write encrypted blobs to the session record (per provider).\n * - Derive minimal metadata (scopes/expiry) for later claims-only exposure.\n */\n willStoreTokens = 'willStoreTokens',\n\n // ---------- Access (read path) ----------\n\n /** Authorize and prepare a session read.\n * Responsibilities:\n * - Validate access to the session; attach read-scoped providers if required.\n * - Optionally shape a partial view before execute.\n */\n willGetSession = 'willGetSession',\n\n /** Post-process the session view.\n * Responsibilities:\n * - Redact/transform/derive fields for the final response.\n * - Set `ctx.output` to a `SessionContextView`.\n */\n didGetSession = 'didGetSession',\n\n // ---------- Disposal ----------\n\n /** Announce shutdown and allow flush/cleanup.\n * Responsibilities:\n * - Close streams, unsubscribe listeners, schedule disposers.\n */\n willDisposeSession = 'willDisposeSession',\n\n /** Confirm teardown and emit metrics.\n * Responsibilities:\n * - Final confirmation of resource release; summarize outcome.\n */\n didDisposeSession = 'didDisposeSession',\n\n // ---------- Finalize / audit / metrics / errors ----------\n\n /** Optional “late finally” hook if you need a single place before audit/metrics.\n * Responsibilities:\n * - Last-chance cleanup across success/error paths (idempotent, non-throwing).\n * Notes:\n * - Include this stage in your plan’s `finalize` array to activate.\n */\n willFinalize = 'willFinalize',\n\n /** Centralized error handler.\n * Responsibilities:\n * - Redact sensitive data; map internal errors to public codes.\n * - Optionally `ctx.respond({ error })` or `ctx.abort(...)`.\n * Notes:\n * - Should not throw; runs before audit/metrics finalize.\n */\n onError = 'onError',\n\n /** Pre-audit collection on both success and error paths.\n * Responsibilities:\n * - Build audit envelope (actor, sessionId, providers touched).\n * - Normalize and strip secrets (no raw tokens).\n */\n willAudit = 'willAudit',\n\n /** Persist/emit the audit record.\n * Responsibilities:\n * - Write to audit sink(s) with outcome and timings.\n * - Correlate via `ctx.requestId`/`ctx.sessionId`.\n */\n didAudit = 'didAudit',\n\n /** Telemetry/metrics emission for both success and errors.\n * Responsibilities:\n * - Counters & timings (create/get/dispose/auth/exchange/store).\n * - Error code/tag cardinality kept small for SLOs/alerts.\n * Constraints:\n * - Non-throwing; must not alter control flow.\n */\n onMetrics = 'onMetrics',\n}\n"]}
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Lifecycle stages for tool invocation.
3
+ *
4
+ * Ordering notes:
5
+ * - "will*" stages run before the action; "did*" run after.
6
+ * - Higher `priority()` runs earlier for "will*" (outermost for wrappers), and later for "did*".
7
+ * - `aroundExecute` wraps the actual execution block (including will/didExecute inside).
8
+ *
9
+ * Control flow:
10
+ * - Hooks may call `ctx.respond(value)` to short-circuit with a value.
11
+ * - Hooks may call `ctx.abort(reason, code?, httpStatus?)` to deny/stop.
12
+ * - Hooks may call `ctx.retryAfter(ms, reason?)` to signal backoff.
13
+ */
14
+ export declare enum ToolHookStage {
15
+ /** Bind DI providers needed for this invocation (from ctor tokens + hook/tool `provide()`).
16
+ * Runs very early so later hooks can use `ctx.get(...)`. */
17
+ willBindProviders = "willBindProviders",
18
+ /** Last chance to populate/shape the invocation context (user, tenant, attrs, ids). */
19
+ willCreateInvokeContext = "willCreateInvokeContext",
20
+ /** Post-context creation; good for sanity checks, tracing decorations. */
21
+ didCreateInvokeContext = "didCreateInvokeContext",
22
+ /** Authorization gate (roles/scopes/RBAC/ABAC). May `abort()` if unauthorized. */
23
+ willAuthorize = "willAuthorize",
24
+ /** Consent gate. May `respond()` with a consent challenge or `abort()` if missing consent. */
25
+ willCheckConsent = "willCheckConsent",
26
+ /** Feature-flag gate (enable/disable per user/tenant/experiment). May `abort()`. */
27
+ willCheckFeatureFlags = "willCheckFeatureFlags",
28
+ /** Acquire rate-limit quota. May `retryAfter()` or `abort()` on exhaustion. */
29
+ willAcquireQuota = "willAcquireQuota",
30
+ /** Release rate-limit quota (best-effort; typically run in `finally`). */
31
+ didReleaseQuota = "didReleaseQuota",
32
+ /** Acquire concurrency slot/semaphore. May `retryAfter()` or `abort()`. */
33
+ willAcquireSemaphore = "willAcquireSemaphore",
34
+ /** Release concurrency slot/semaphore (best-effort). */
35
+ didReleaseSemaphore = "didReleaseSemaphore",
36
+ /** Parse/coerce raw input (types, defaults). Mutate `ctx.input` as needed. */
37
+ willParseInput = "willParseInput",
38
+ /** Validate business rules for input. May `abort()` on violations. */
39
+ willValidateInput = "willValidateInput",
40
+ /** Normalize/canonicalize input (ids → uuids, trim, sort fields, etc.). */
41
+ willNormalizeInput = "willNormalizeInput",
42
+ /** Apply DLP/minimization to input (mask/drop/hash fields). */
43
+ willRedactInput = "willRedactInput",
44
+ /** Inject credentials/secrets (tokens, API keys) into context or input. */
45
+ willInjectSecrets = "willInjectSecrets",
46
+ /** Attempt to serve from cache. May `respond(cachedValue)` to short-circuit. */
47
+ willReadCache = "willReadCache",
48
+ /** Metrics/telemetry for cache hit; typically emitted by cache plugin. */
49
+ didCacheHit = "didCacheHit",
50
+ /** Metrics/telemetry for cache miss; typically emitted by cache plugin. */
51
+ didCacheMiss = "didCacheMiss",
52
+ /** Write result to cache after successful execution. */
53
+ willWriteCache = "willWriteCache",
54
+ /** Around wrapper for execution (timeouts/retries/circuit/tracing). Must call `next()` unless short-circuiting. */
55
+ aroundExecute = "aroundExecute",
56
+ /** Right before calling the tool implementation; may mutate `ctx.input`. */
57
+ willExecute = "willExecute",
58
+ /** Right after tool returns; `ctx.output` is available for downstream hooks. */
59
+ didExecute = "didExecute",
60
+ /** Apply DLP/minimization to output (mask/drop/truncate sensitive fields). */
61
+ willRedactOutput = "willRedactOutput",
62
+ /** Validate output against business/schema rules. May `abort()` or fix. */
63
+ willValidateOutput = "willValidateOutput",
64
+ /** Transform output shape (projection/mapping/pagination). Mutate `ctx.output`. */
65
+ willTransformOutput = "willTransformOutput",
66
+ /** Called on each retry attempt by a retry wrapper (emit metrics/backoff hints). */
67
+ onRetry = "onRetry",
68
+ /** Called when retries are exhausted and execution gives up. */
69
+ onGiveUp = "onGiveUp",
70
+ /** Prepare audit payload (apply redaction) and/or write audit logs. */
71
+ willAudit = "willAudit",
72
+ /** Post-audit hook (confirm persistence, forward to sinks). */
73
+ didAudit = "didAudit",
74
+ /** Emit metrics (counters, histograms, traces). */
75
+ onMetrics = "onMetrics",
76
+ /** Error handler for unexpected failures or control errors. Can map/normalize errors. */
77
+ onError = "onError",
78
+ /** Always runs at the very end (success or error). Cleanup/releases here. */
79
+ willFinalizeInvoke = "willFinalizeInvoke"
80
+ }
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ToolHookStage = void 0;
4
+ /**
5
+ * Lifecycle stages for tool invocation.
6
+ *
7
+ * Ordering notes:
8
+ * - "will*" stages run before the action; "did*" run after.
9
+ * - Higher `priority()` runs earlier for "will*" (outermost for wrappers), and later for "did*".
10
+ * - `aroundExecute` wraps the actual execution block (including will/didExecute inside).
11
+ *
12
+ * Control flow:
13
+ * - Hooks may call `ctx.respond(value)` to short-circuit with a value.
14
+ * - Hooks may call `ctx.abort(reason, code?, httpStatus?)` to deny/stop.
15
+ * - Hooks may call `ctx.retryAfter(ms, reason?)` to signal backoff.
16
+ */
17
+ var ToolHookStage;
18
+ (function (ToolHookStage) {
19
+ /** Bind DI providers needed for this invocation (from ctor tokens + hook/tool `provide()`).
20
+ * Runs very early so later hooks can use `ctx.get(...)`. */
21
+ ToolHookStage["willBindProviders"] = "willBindProviders";
22
+ /** Last chance to populate/shape the invocation context (user, tenant, attrs, ids). */
23
+ ToolHookStage["willCreateInvokeContext"] = "willCreateInvokeContext";
24
+ /** Post-context creation; good for sanity checks, tracing decorations. */
25
+ ToolHookStage["didCreateInvokeContext"] = "didCreateInvokeContext";
26
+ /** Authorization gate (roles/scopes/RBAC/ABAC). May `abort()` if unauthorized. */
27
+ ToolHookStage["willAuthorize"] = "willAuthorize";
28
+ /** Consent gate. May `respond()` with a consent challenge or `abort()` if missing consent. */
29
+ ToolHookStage["willCheckConsent"] = "willCheckConsent";
30
+ /** Feature-flag gate (enable/disable per user/tenant/experiment). May `abort()`. */
31
+ ToolHookStage["willCheckFeatureFlags"] = "willCheckFeatureFlags";
32
+ // ---------------- Capacity & Resilience ----------------
33
+ /** Acquire rate-limit quota. May `retryAfter()` or `abort()` on exhaustion. */
34
+ ToolHookStage["willAcquireQuota"] = "willAcquireQuota";
35
+ /** Release rate-limit quota (best-effort; typically run in `finally`). */
36
+ ToolHookStage["didReleaseQuota"] = "didReleaseQuota";
37
+ /** Acquire concurrency slot/semaphore. May `retryAfter()` or `abort()`. */
38
+ ToolHookStage["willAcquireSemaphore"] = "willAcquireSemaphore";
39
+ /** Release concurrency slot/semaphore (best-effort). */
40
+ ToolHookStage["didReleaseSemaphore"] = "didReleaseSemaphore";
41
+ // ---------------- Input shaping ----------------
42
+ /** Parse/coerce raw input (types, defaults). Mutate `ctx.input` as needed. */
43
+ ToolHookStage["willParseInput"] = "willParseInput";
44
+ /** Validate business rules for input. May `abort()` on violations. */
45
+ ToolHookStage["willValidateInput"] = "willValidateInput";
46
+ /** Normalize/canonicalize input (ids → uuids, trim, sort fields, etc.). */
47
+ ToolHookStage["willNormalizeInput"] = "willNormalizeInput";
48
+ /** Apply DLP/minimization to input (mask/drop/hash fields). */
49
+ ToolHookStage["willRedactInput"] = "willRedactInput";
50
+ /** Inject credentials/secrets (tokens, API keys) into context or input. */
51
+ ToolHookStage["willInjectSecrets"] = "willInjectSecrets";
52
+ // ---------------- Caching ----------------
53
+ /** Attempt to serve from cache. May `respond(cachedValue)` to short-circuit. */
54
+ ToolHookStage["willReadCache"] = "willReadCache";
55
+ /** Metrics/telemetry for cache hit; typically emitted by cache plugin. */
56
+ ToolHookStage["didCacheHit"] = "didCacheHit";
57
+ /** Metrics/telemetry for cache miss; typically emitted by cache plugin. */
58
+ ToolHookStage["didCacheMiss"] = "didCacheMiss";
59
+ /** Write result to cache after successful execution. */
60
+ ToolHookStage["willWriteCache"] = "willWriteCache";
61
+ // ---------------- Execution ----------------
62
+ /** Around wrapper for execution (timeouts/retries/circuit/tracing). Must call `next()` unless short-circuiting. */
63
+ ToolHookStage["aroundExecute"] = "aroundExecute";
64
+ /** Right before calling the tool implementation; may mutate `ctx.input`. */
65
+ ToolHookStage["willExecute"] = "willExecute";
66
+ /** Right after tool returns; `ctx.output` is available for downstream hooks. */
67
+ ToolHookStage["didExecute"] = "didExecute";
68
+ // ---------------- Output shaping ----------------
69
+ /** Apply DLP/minimization to output (mask/drop/truncate sensitive fields). */
70
+ ToolHookStage["willRedactOutput"] = "willRedactOutput";
71
+ /** Validate output against business/schema rules. May `abort()` or fix. */
72
+ ToolHookStage["willValidateOutput"] = "willValidateOutput";
73
+ /** Transform output shape (projection/mapping/pagination). Mutate `ctx.output`. */
74
+ ToolHookStage["willTransformOutput"] = "willTransformOutput";
75
+ // ---------------- Retry & Observability ----------------
76
+ /** Called on each retry attempt by a retry wrapper (emit metrics/backoff hints). */
77
+ ToolHookStage["onRetry"] = "onRetry";
78
+ /** Called when retries are exhausted and execution gives up. */
79
+ ToolHookStage["onGiveUp"] = "onGiveUp";
80
+ /** Prepare audit payload (apply redaction) and/or write audit logs. */
81
+ ToolHookStage["willAudit"] = "willAudit";
82
+ /** Post-audit hook (confirm persistence, forward to sinks). */
83
+ ToolHookStage["didAudit"] = "didAudit";
84
+ /** Emit metrics (counters, histograms, traces). */
85
+ ToolHookStage["onMetrics"] = "onMetrics";
86
+ // ---------------- Error & Finalization ----------------
87
+ /** Error handler for unexpected failures or control errors. Can map/normalize errors. */
88
+ ToolHookStage["onError"] = "onError";
89
+ /** Always runs at the very end (success or error). Cleanup/releases here. */
90
+ ToolHookStage["willFinalizeInvoke"] = "willFinalizeInvoke";
91
+ })(ToolHookStage || (exports.ToolHookStage = ToolHookStage = {}));
92
+ //# sourceMappingURL=tool-hook.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-hook.interface.js","sourceRoot":"","sources":["../../../src/interfaces/tool-hook.interface.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;GAYG;AACH,IAAY,aA+GX;AA/GD,WAAY,aAAa;IACvB;gEAC4D;IAC5D,wDAAuC,CAAA;IAEvC,uFAAuF;IACvF,oEAAmD,CAAA;IAEnD,0EAA0E;IAC1E,kEAAiD,CAAA;IAEjD,kFAAkF;IAClF,gDAA+B,CAAA;IAE/B,8FAA8F;IAC9F,sDAAqC,CAAA;IAErC,oFAAoF;IACpF,gEAA+C,CAAA;IAE/C,0DAA0D;IAE1D,+EAA+E;IAC/E,sDAAqC,CAAA;IAErC,0EAA0E;IAC1E,oDAAmC,CAAA;IAEnC,2EAA2E;IAC3E,8DAA6C,CAAA;IAE7C,wDAAwD;IACxD,4DAA2C,CAAA;IAE3C,kDAAkD;IAElD,8EAA8E;IAC9E,kDAAiC,CAAA;IAEjC,sEAAsE;IACtE,wDAAuC,CAAA;IAEvC,2EAA2E;IAC3E,0DAAyC,CAAA;IAEzC,+DAA+D;IAC/D,oDAAmC,CAAA;IAEnC,2EAA2E;IAC3E,wDAAuC,CAAA;IAEvC,4CAA4C;IAE5C,gFAAgF;IAChF,gDAA+B,CAAA;IAE/B,0EAA0E;IAC1E,4CAA2B,CAAA;IAE3B,2EAA2E;IAC3E,8CAA6B,CAAA;IAE7B,wDAAwD;IACxD,kDAAiC,CAAA;IAEjC,8CAA8C;IAE9C,mHAAmH;IACnH,gDAA+B,CAAA;IAE/B,4EAA4E;IAC5E,4CAA2B,CAAA;IAE3B,gFAAgF;IAChF,0CAAyB,CAAA;IAEzB,mDAAmD;IAEnD,8EAA8E;IAC9E,sDAAqC,CAAA;IAErC,2EAA2E;IAC3E,0DAAyC,CAAA;IAEzC,mFAAmF;IACnF,4DAA2C,CAAA;IAE3C,0DAA0D;IAE1D,oFAAoF;IACpF,oCAAmB,CAAA;IAEnB,gEAAgE;IAChE,sCAAqB,CAAA;IAErB,uEAAuE;IACvE,wCAAuB,CAAA;IAEvB,+DAA+D;IAC/D,sCAAqB,CAAA;IAErB,mDAAmD;IACnD,wCAAuB,CAAA;IAEvB,yDAAyD;IAEzD,yFAAyF;IACzF,oCAAmB,CAAA;IAEnB,6EAA6E;IAC7E,0DAAyC,CAAA;AAC3C,CAAC,EA/GW,aAAa,6BAAb,aAAa,QA+GxB","sourcesContent":["/**\n * Lifecycle stages for tool invocation.\n *\n * Ordering notes:\n * - \"will*\" stages run before the action; \"did*\" run after.\n * - Higher `priority()` runs earlier for \"will*\" (outermost for wrappers), and later for \"did*\".\n * - `aroundExecute` wraps the actual execution block (including will/didExecute inside).\n *\n * Control flow:\n * - Hooks may call `ctx.respond(value)` to short-circuit with a value.\n * - Hooks may call `ctx.abort(reason, code?, httpStatus?)` to deny/stop.\n * - Hooks may call `ctx.retryAfter(ms, reason?)` to signal backoff.\n */\nexport enum ToolHookStage {\n /** Bind DI providers needed for this invocation (from ctor tokens + hook/tool `provide()`).\n * Runs very early so later hooks can use `ctx.get(...)`. */\n willBindProviders = 'willBindProviders',\n\n /** Last chance to populate/shape the invocation context (user, tenant, attrs, ids). */\n willCreateInvokeContext = 'willCreateInvokeContext',\n\n /** Post-context creation; good for sanity checks, tracing decorations. */\n didCreateInvokeContext = 'didCreateInvokeContext',\n\n /** Authorization gate (roles/scopes/RBAC/ABAC). May `abort()` if unauthorized. */\n willAuthorize = 'willAuthorize',\n\n /** Consent gate. May `respond()` with a consent challenge or `abort()` if missing consent. */\n willCheckConsent = 'willCheckConsent',\n\n /** Feature-flag gate (enable/disable per user/tenant/experiment). May `abort()`. */\n willCheckFeatureFlags = 'willCheckFeatureFlags',\n\n // ---------------- Capacity & Resilience ----------------\n\n /** Acquire rate-limit quota. May `retryAfter()` or `abort()` on exhaustion. */\n willAcquireQuota = 'willAcquireQuota',\n\n /** Release rate-limit quota (best-effort; typically run in `finally`). */\n didReleaseQuota = 'didReleaseQuota',\n\n /** Acquire concurrency slot/semaphore. May `retryAfter()` or `abort()`. */\n willAcquireSemaphore = 'willAcquireSemaphore',\n\n /** Release concurrency slot/semaphore (best-effort). */\n didReleaseSemaphore = 'didReleaseSemaphore',\n\n // ---------------- Input shaping ----------------\n\n /** Parse/coerce raw input (types, defaults). Mutate `ctx.input` as needed. */\n willParseInput = 'willParseInput',\n\n /** Validate business rules for input. May `abort()` on violations. */\n willValidateInput = 'willValidateInput',\n\n /** Normalize/canonicalize input (ids → uuids, trim, sort fields, etc.). */\n willNormalizeInput = 'willNormalizeInput',\n\n /** Apply DLP/minimization to input (mask/drop/hash fields). */\n willRedactInput = 'willRedactInput',\n\n /** Inject credentials/secrets (tokens, API keys) into context or input. */\n willInjectSecrets = 'willInjectSecrets',\n\n // ---------------- Caching ----------------\n\n /** Attempt to serve from cache. May `respond(cachedValue)` to short-circuit. */\n willReadCache = 'willReadCache',\n\n /** Metrics/telemetry for cache hit; typically emitted by cache plugin. */\n didCacheHit = 'didCacheHit',\n\n /** Metrics/telemetry for cache miss; typically emitted by cache plugin. */\n didCacheMiss = 'didCacheMiss',\n\n /** Write result to cache after successful execution. */\n willWriteCache = 'willWriteCache',\n\n // ---------------- Execution ----------------\n\n /** Around wrapper for execution (timeouts/retries/circuit/tracing). Must call `next()` unless short-circuiting. */\n aroundExecute = 'aroundExecute',\n\n /** Right before calling the tool implementation; may mutate `ctx.input`. */\n willExecute = 'willExecute',\n\n /** Right after tool returns; `ctx.output` is available for downstream hooks. */\n didExecute = 'didExecute',\n\n // ---------------- Output shaping ----------------\n\n /** Apply DLP/minimization to output (mask/drop/truncate sensitive fields). */\n willRedactOutput = 'willRedactOutput',\n\n /** Validate output against business/schema rules. May `abort()` or fix. */\n willValidateOutput = 'willValidateOutput',\n\n /** Transform output shape (projection/mapping/pagination). Mutate `ctx.output`. */\n willTransformOutput = 'willTransformOutput',\n\n // ---------------- Retry & Observability ----------------\n\n /** Called on each retry attempt by a retry wrapper (emit metrics/backoff hints). */\n onRetry = 'onRetry',\n\n /** Called when retries are exhausted and execution gives up. */\n onGiveUp = 'onGiveUp',\n\n /** Prepare audit payload (apply redaction) and/or write audit logs. */\n willAudit = 'willAudit',\n\n /** Post-audit hook (confirm persistence, forward to sinks). */\n didAudit = 'didAudit',\n\n /** Emit metrics (counters, histograms, traces). */\n onMetrics = 'onMetrics',\n\n // ---------------- Error & Finalization ----------------\n\n /** Error handler for unexpected failures or control errors. Can map/normalize errors. */\n onError = 'onError',\n\n /** Always runs at the very end (success or error). Cleanup/releases here. */\n willFinalizeInvoke = 'willFinalizeInvoke',\n}\n"]}
@@ -0,0 +1,45 @@
1
+ import { FuncType, Token, Type } from "./base.interface";
2
+ import { ProviderRegistryInterface } from "./internal";
3
+ import { ToolMetadata } from "../metadata";
4
+ import { FrontMcpLogger } from "./logger.interface";
5
+ import { URL } from "url";
6
+ export type ToolType<T = any> = Type<T> | FuncType<T>;
7
+ type HistoryEntry<T> = {
8
+ at: number;
9
+ stage?: string;
10
+ value: T | undefined;
11
+ note?: string;
12
+ };
13
+ export declare abstract class ToolContext<In, Out> {
14
+ private providers;
15
+ private session;
16
+ protected readonly runId: string;
17
+ protected readonly toolId: string;
18
+ protected readonly toolName: string;
19
+ protected readonly metadata: ToolMetadata;
20
+ protected readonly logger: FrontMcpLogger;
21
+ protected activeStage: string;
22
+ private _rawInput?;
23
+ private _input?;
24
+ private _outputDraft?;
25
+ private _output?;
26
+ private _error?;
27
+ private readonly _inputHistory;
28
+ private readonly _outputHistory;
29
+ constructor(metadata: ToolMetadata, input: In, providers: ProviderRegistryInterface, logger: FrontMcpLogger, session: any);
30
+ abstract execute(input: In): Promise<Out>;
31
+ get<T>(token: Token<T>): T;
32
+ tryGet<T>(token: Token<T>): T | undefined;
33
+ get input(): In;
34
+ set input(v: In | undefined);
35
+ get inputHistory(): ReadonlyArray<HistoryEntry<In>>;
36
+ get output(): Out | undefined;
37
+ set output(v: Out | undefined);
38
+ get outputHistory(): ReadonlyArray<HistoryEntry<Out>>;
39
+ protected respond(value: Out): never;
40
+ /** Fail the run (invoker will run error/finalize). */
41
+ protected fail(err: Error): never;
42
+ mark(stage: string): void;
43
+ fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
44
+ }
45
+ export {};
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ToolContext = void 0;
4
+ const crypto_1 = require("crypto");
5
+ const flow_interface_1 = require("./flow.interface");
6
+ class ToolContext {
7
+ providers;
8
+ session; // TODO: type this
9
+ runId;
10
+ toolId;
11
+ toolName;
12
+ metadata;
13
+ logger;
14
+ activeStage;
15
+ // ---- INPUT storages (backing fields)
16
+ _rawInput;
17
+ _input;
18
+ // ---- OUTPUT storages (backing fields)
19
+ _outputDraft;
20
+ _output;
21
+ _error;
22
+ // ---- histories
23
+ _inputHistory = [];
24
+ _outputHistory = [];
25
+ constructor(metadata, input, providers, logger, session) {
26
+ this.runId = (0, crypto_1.randomUUID)();
27
+ this.toolName = metadata.name;
28
+ this.toolId = metadata.id ?? metadata.name;
29
+ this.metadata = metadata;
30
+ this._input = input;
31
+ this.providers = providers;
32
+ this.logger = logger.child(`tool:${this.toolId}`);
33
+ this.session = session;
34
+ }
35
+ get(token) {
36
+ return this.providers.get(token);
37
+ }
38
+ tryGet(token) {
39
+ try {
40
+ return this.providers.get(token);
41
+ }
42
+ catch (e) {
43
+ this.logger.warn("Requesting provider that doesn't exist: ", token);
44
+ return undefined;
45
+ }
46
+ }
47
+ get input() {
48
+ return this._input;
49
+ }
50
+ set input(v) {
51
+ this._input = v;
52
+ this._inputHistory.push({
53
+ at: Date.now(),
54
+ stage: this.activeStage,
55
+ value: v,
56
+ });
57
+ }
58
+ get inputHistory() {
59
+ return this._inputHistory;
60
+ }
61
+ get output() {
62
+ return this._output;
63
+ }
64
+ set output(v) {
65
+ this._output = v;
66
+ this._outputHistory.push({ at: Date.now(), stage: this.activeStage, value: v, });
67
+ }
68
+ get outputHistory() {
69
+ return this._outputHistory;
70
+ }
71
+ respond(value) {
72
+ // record validated output and surface the value via control flow
73
+ this.output = value;
74
+ flow_interface_1.FlowControl.respond(value);
75
+ }
76
+ /** Fail the run (invoker will run error/finalize). */
77
+ fail(err) {
78
+ this._error = err;
79
+ flow_interface_1.FlowControl.fail(err);
80
+ }
81
+ mark(stage) {
82
+ this.activeStage = stage;
83
+ }
84
+ fetch(input, init) {
85
+ return this.session.fetch(input, init);
86
+ }
87
+ }
88
+ exports.ToolContext = ToolContext;
89
+ //# sourceMappingURL=tool.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool.interface.js","sourceRoot":"","sources":["../../../src/interfaces/tool.interface.ts"],"names":[],"mappings":";;;AAAA,mCAAkC;AAKlC,qDAA6C;AAc7C,MAAsB,WAAW;IACvB,SAAS,CAA4B;IACrC,OAAO,CAAM,CAAC,kBAAkB;IAErB,KAAK,CAAS;IACd,MAAM,CAAS;IACf,QAAQ,CAAS;IACjB,QAAQ,CAAe;IACvB,MAAM,CAAiB;IAEhC,WAAW,CAAS;IAE9B,uCAAuC;IAC/B,SAAS,CAAqB;IAC9B,MAAM,CAAM;IAEpB,wCAAwC;IAChC,YAAY,CAAsB;IAClC,OAAO,CAAO;IAEd,MAAM,CAAS;IAEvB,iBAAiB;IACA,aAAa,GAAuB,EAAE,CAAC;IACvC,cAAc,GAAwB,EAAE,CAAC;IAG1D,YAAY,QAAsB,EAAE,KAAS,EAAE,SAAoC,EAAE,MAAsB,EAAE,OAAY;QACvH,IAAI,CAAC,KAAK,GAAG,IAAA,mBAAU,GAAE,CAAC;QAC1B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC,IAAI,CAAC;QAC9B,IAAI,CAAC,MAAM,GAAG,QAAQ,CAAC,EAAE,IAAI,QAAQ,CAAC,IAAI,CAAC;QAC3C,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,QAAQ,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;QAClD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAID,GAAG,CAAI,KAAe;QACpB,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACnC,CAAC;IAED,MAAM,CAAI,KAAe;QACvB,IAAI,CAAC;YACH,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACnC,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,0CAA0C,EAAE,KAAK,CAAC,CAAC;YACpE,OAAO,SAAS,CAAC;QACnB,CAAC;IACH,CAAC;IAED,IAAW,KAAK;QACd,OAAO,IAAI,CAAC,MAAY,CAAC;IAC3B,CAAC;IAED,IAAW,KAAK,CAAC,CAAiB;QAChC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;QAChB,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC;YACtB,EAAE,EAAE,IAAI,CAAC,GAAG,EAAE;YACd,KAAK,EAAE,IAAI,CAAC,WAAW;YACvB,KAAK,EAAE,CAAC;SACT,CAAC,CAAC;IACL,CAAC;IAED,IAAW,YAAY;QACrB,OAAO,IAAI,CAAC,aAAa,CAAC;IAC5B,CAAC;IAED,IAAW,MAAM;QACf,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED,IAAW,MAAM,CAAC,CAAkB;QAClC,IAAI,CAAC,OAAO,GAAG,CAAC,CAAC;QACjB,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,EAAC,EAAE,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,IAAI,CAAC,WAAW,EAAE,KAAK,EAAE,CAAC,GAAE,CAAC,CAAC;IACjF,CAAC;IAED,IAAW,aAAa;QACtB,OAAO,IAAI,CAAC,cAAc,CAAC;IAC7B,CAAC;IAES,OAAO,CAAC,KAAU;QAC1B,iEAAiE;QACjE,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,4BAAW,CAAC,OAAO,CAAM,KAAK,CAAC,CAAC;IAClC,CAAC;IAED,sDAAsD;IAC5C,IAAI,CAAC,GAAU;QACvB,IAAI,CAAC,MAAM,GAAG,GAAG,CAAC;QAClB,4BAAW,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACxB,CAAC;IAED,IAAI,CAAC,KAAa;QAChB,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;IAC3B,CAAC;IAED,KAAK,CAAC,KAAwB,EAAE,IAAkB;QAChD,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACzC,CAAC;CACF;AAtGD,kCAsGC","sourcesContent":["import {randomUUID} from \"crypto\";\nimport {FuncType, Token, Type} from \"./base.interface\";\nimport {ProviderRegistryInterface} from \"./internal\";\nimport {ToolMetadata} from \"../metadata\";\nimport {FrontMcpLogger} from \"./logger.interface\";\nimport {FlowControl} from \"./flow.interface\";\nimport {URL} from \"url\";\n\nexport type ToolType<T = any> =\n | Type<T>\n | FuncType<T>\n\ntype HistoryEntry<T> = {\n at: number;\n stage?: string;\n value: T | undefined;\n note?: string;\n};\n\nexport abstract class ToolContext<In, Out> {\n private providers: ProviderRegistryInterface;\n private session: any; // TODO: type this\n\n protected readonly runId: string;\n protected readonly toolId: string;\n protected readonly toolName: string;\n protected readonly metadata: ToolMetadata;\n protected readonly logger: FrontMcpLogger;\n\n protected activeStage: string;\n\n // ---- INPUT storages (backing fields)\n private _rawInput?: Partial<In> | any;\n private _input?: In;\n\n // ---- OUTPUT storages (backing fields)\n private _outputDraft?: Partial<Out> | any;\n private _output?: Out;\n\n private _error?: Error;\n\n // ---- histories\n private readonly _inputHistory: HistoryEntry<In>[] = [];\n private readonly _outputHistory: HistoryEntry<Out>[] = [];\n\n\n constructor(metadata: ToolMetadata, input: In, providers: ProviderRegistryInterface, logger: FrontMcpLogger, session: any) {\n this.runId = randomUUID();\n this.toolName = metadata.name;\n this.toolId = metadata.id ?? metadata.name;\n this.metadata = metadata;\n this._input = input;\n this.providers = providers;\n this.logger = logger.child(`tool:${this.toolId}`);\n this.session = session;\n }\n\n abstract execute(input: In): Promise<Out>;\n\n get<T>(token: Token<T>): T {\n return this.providers.get(token);\n }\n\n tryGet<T>(token: Token<T>): T | undefined {\n try {\n return this.providers.get(token);\n } catch (e) {\n this.logger.warn(\"Requesting provider that doesn't exist: \", token);\n return undefined;\n }\n }\n\n public get input(): In {\n return this._input as In;\n }\n\n public set input(v: In | undefined) {\n this._input = v;\n this._inputHistory.push({\n at: Date.now(),\n stage: this.activeStage,\n value: v,\n });\n }\n\n public get inputHistory(): ReadonlyArray<HistoryEntry<In>> {\n return this._inputHistory;\n }\n\n public get output(): Out | undefined {\n return this._output;\n }\n\n public set output(v: Out | undefined) {\n this._output = v;\n this._outputHistory.push({at: Date.now(), stage: this.activeStage, value: v,});\n }\n\n public get outputHistory(): ReadonlyArray<HistoryEntry<Out>> {\n return this._outputHistory;\n }\n\n protected respond(value: Out): never {\n // record validated output and surface the value via control flow\n this.output = value;\n FlowControl.respond<Out>(value);\n }\n\n /** Fail the run (invoker will run error/finalize). */\n protected fail(err: Error): never {\n this._error = err;\n FlowControl.fail(err);\n }\n\n mark(stage: string): void {\n this.activeStage = stage;\n }\n\n fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response> {\n return this.session.fetch(input, init);\n }\n}\n\n"]}
@@ -0,0 +1,22 @@
1
+ import { z } from 'zod';
2
+ /**
3
+ * Declarative metadata describing what a FrontMcpAdapter contributes at app scope.
4
+ */
5
+ export interface AdapterMetadata {
6
+ id?: string;
7
+ name: string;
8
+ description?: string;
9
+ }
10
+ export declare const frontMcpAdapterMetadataSchema: z.ZodObject<{
11
+ id: z.ZodOptional<z.ZodString>;
12
+ name: z.ZodString;
13
+ description: z.ZodOptional<z.ZodString>;
14
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
15
+ id: z.ZodOptional<z.ZodString>;
16
+ name: z.ZodString;
17
+ description: z.ZodOptional<z.ZodString>;
18
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
19
+ id: z.ZodOptional<z.ZodString>;
20
+ name: z.ZodString;
21
+ description: z.ZodOptional<z.ZodString>;
22
+ }, z.ZodTypeAny, "passthrough">>;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.frontMcpAdapterMetadataSchema = void 0;
4
+ const zod_1 = require("zod");
5
+ exports.frontMcpAdapterMetadataSchema = zod_1.z.object({
6
+ id: zod_1.z.string().optional(),
7
+ name: zod_1.z.string().min(1),
8
+ description: zod_1.z.string().optional(),
9
+ }).passthrough();
10
+ //# sourceMappingURL=adapter.metadata.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adapter.metadata.js","sourceRoot":"","sources":["../../../src/metadata/adapter.metadata.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AAcX,QAAA,6BAA6B,GAAG,OAAC,CAAC,MAAM,CAAC;IACpD,EAAE,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IACzB,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACvB,WAAW,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CACI,CAAC,CAAC,WAAW,EAAE,CAAC","sourcesContent":["import { z } from 'zod';\nimport { RawZodShape } from '../types';\n\n\n/**\n * Declarative metadata describing what a FrontMcpAdapter contributes at app scope.\n */\nexport interface AdapterMetadata {\n id?: string;\n name: string;\n description?: string;\n}\n\n\nexport const frontMcpAdapterMetadataSchema = z.object({\n id: z.string().optional(),\n name: z.string().min(1),\n description: z.string().optional(),\n} satisfies RawZodShape<AdapterMetadata>).passthrough();\n"]}