@noodleseed/one 0.122.0 → 0.124.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 (231) hide show
  1. package/dist/cli.d.ts.map +1 -1
  2. package/dist/cli.js +3 -0
  3. package/dist/cli.js.map +1 -1
  4. package/dist/commands/catalog-data-hosted-observability.d.ts.map +1 -1
  5. package/dist/commands/catalog-data-hosted-observability.js +33 -0
  6. package/dist/commands/catalog-data-hosted-observability.js.map +1 -1
  7. package/dist/commands/deploy-version-resolution.js +1 -1
  8. package/dist/commands/deploy-version-resolution.js.map +1 -1
  9. package/dist/commands/knowledge.d.ts +7 -0
  10. package/dist/commands/knowledge.d.ts.map +1 -0
  11. package/dist/commands/knowledge.js +129 -0
  12. package/dist/commands/knowledge.js.map +1 -0
  13. package/dist/deploy.d.ts.map +1 -1
  14. package/dist/deploy.js +19 -2
  15. package/dist/deploy.js.map +1 -1
  16. package/node_modules/@noodle-borg/agent-kit/dist/curated/command-groups.d.ts.map +1 -1
  17. package/node_modules/@noodle-borg/agent-kit/dist/curated/command-groups.js +4 -0
  18. package/node_modules/@noodle-borg/agent-kit/dist/curated/command-groups.js.map +1 -1
  19. package/node_modules/@noodle-borg/agent-kit/dist/generated/example-files.js +3 -3
  20. package/node_modules/@noodle-borg/agent-kit/dist/generated/example-files.js.map +1 -1
  21. package/node_modules/@noodle-borg/agent-kit/dist/generated/surface.d.ts.map +1 -1
  22. package/node_modules/@noodle-borg/agent-kit/dist/generated/surface.js +1 -0
  23. package/node_modules/@noodle-borg/agent-kit/dist/generated/surface.js.map +1 -1
  24. package/node_modules/@noodle-borg/agent-kit/dist/skill-authoring-refs.d.ts.map +1 -1
  25. package/node_modules/@noodle-borg/agent-kit/dist/skill-authoring-refs.js +2 -0
  26. package/node_modules/@noodle-borg/agent-kit/dist/skill-authoring-refs.js.map +1 -1
  27. package/node_modules/@noodle-borg/agent-kit/package.json +1 -1
  28. package/node_modules/@noodle-borg/assistant-gateway/dist/artifact-projection.d.ts +1 -1
  29. package/node_modules/@noodle-borg/assistant-gateway/dist/artifact-projection.d.ts.map +1 -1
  30. package/node_modules/@noodle-borg/assistant-gateway/dist/artifact-projection.js +7 -1
  31. package/node_modules/@noodle-borg/assistant-gateway/dist/artifact-projection.js.map +1 -1
  32. package/node_modules/@noodle-borg/{service → assistant-gateway}/dist/assistant-interactive.d.ts +1 -1
  33. package/node_modules/@noodle-borg/{service → assistant-gateway}/dist/assistant-interactive.d.ts.map +1 -1
  34. package/node_modules/@noodle-borg/{service → assistant-gateway}/dist/assistant-interactive.js.map +1 -1
  35. package/node_modules/@noodle-borg/{service → assistant-gateway}/dist/assistant-presentation.d.ts.map +1 -1
  36. package/node_modules/@noodle-borg/{service → assistant-gateway}/dist/assistant-presentation.js +1 -1
  37. package/node_modules/@noodle-borg/{service → assistant-gateway}/dist/assistant-presentation.js.map +1 -1
  38. package/node_modules/@noodle-borg/assistant-gateway/dist/index.d.ts +2 -0
  39. package/node_modules/@noodle-borg/assistant-gateway/dist/index.d.ts.map +1 -1
  40. package/node_modules/@noodle-borg/assistant-gateway/dist/index.js +2 -0
  41. package/node_modules/@noodle-borg/assistant-gateway/dist/index.js.map +1 -1
  42. package/node_modules/@noodle-borg/assistant-gateway/package.json +3 -1
  43. package/node_modules/@noodle-borg/deploy-client/dist/deploy-knowledge.d.ts +21 -0
  44. package/node_modules/@noodle-borg/deploy-client/dist/deploy-knowledge.d.ts.map +1 -0
  45. package/node_modules/@noodle-borg/deploy-client/dist/deploy-knowledge.js +115 -0
  46. package/node_modules/@noodle-borg/deploy-client/dist/deploy-knowledge.js.map +1 -0
  47. package/node_modules/@noodle-borg/deploy-client/dist/index.d.ts +4 -0
  48. package/node_modules/@noodle-borg/deploy-client/dist/index.d.ts.map +1 -0
  49. package/node_modules/@noodle-borg/deploy-client/dist/index.js +4 -0
  50. package/node_modules/@noodle-borg/deploy-client/dist/index.js.map +1 -0
  51. package/node_modules/@noodle-borg/deploy-client/package.json +34 -0
  52. package/node_modules/@noodle-borg/knowledge/dist/bm25.d.ts.map +1 -1
  53. package/node_modules/@noodle-borg/knowledge/dist/bm25.js +4 -0
  54. package/node_modules/@noodle-borg/knowledge/dist/bm25.js.map +1 -1
  55. package/node_modules/@noodle-borg/knowledge/dist/google-agent-search.d.ts +4 -0
  56. package/node_modules/@noodle-borg/knowledge/dist/google-agent-search.d.ts.map +1 -1
  57. package/node_modules/@noodle-borg/knowledge/dist/google-agent-search.js +28 -20
  58. package/node_modules/@noodle-borg/knowledge/dist/google-agent-search.js.map +1 -1
  59. package/node_modules/@noodle-borg/knowledge/dist/postgres-revision-store.d.ts +2 -1
  60. package/node_modules/@noodle-borg/knowledge/dist/postgres-revision-store.d.ts.map +1 -1
  61. package/node_modules/@noodle-borg/knowledge/dist/postgres-revision-store.js +53 -28
  62. package/node_modules/@noodle-borg/knowledge/dist/postgres-revision-store.js.map +1 -1
  63. package/node_modules/@noodle-borg/knowledge/dist/revision-store.d.ts +9 -5
  64. package/node_modules/@noodle-borg/knowledge/dist/revision-store.d.ts.map +1 -1
  65. package/node_modules/@noodle-borg/knowledge/dist/revision-store.js +38 -21
  66. package/node_modules/@noodle-borg/knowledge/dist/revision-store.js.map +1 -1
  67. package/node_modules/@noodle-borg/knowledge/package.json +4 -0
  68. package/node_modules/@noodle-borg/knowledge-operations/dist/codec.d.ts +12 -0
  69. package/node_modules/@noodle-borg/knowledge-operations/dist/codec.d.ts.map +1 -0
  70. package/node_modules/@noodle-borg/knowledge-operations/dist/codec.js +7 -0
  71. package/node_modules/@noodle-borg/knowledge-operations/dist/codec.js.map +1 -0
  72. package/node_modules/@noodle-borg/knowledge-operations/dist/dispatch.d.ts +16 -0
  73. package/node_modules/@noodle-borg/knowledge-operations/dist/dispatch.d.ts.map +1 -0
  74. package/node_modules/@noodle-borg/knowledge-operations/dist/dispatch.js +41 -0
  75. package/node_modules/@noodle-borg/knowledge-operations/dist/dispatch.js.map +1 -0
  76. package/node_modules/@noodle-borg/knowledge-operations/dist/executor.d.ts +40 -0
  77. package/node_modules/@noodle-borg/knowledge-operations/dist/executor.d.ts.map +1 -0
  78. package/node_modules/@noodle-borg/knowledge-operations/dist/executor.js +54 -0
  79. package/node_modules/@noodle-borg/knowledge-operations/dist/executor.js.map +1 -0
  80. package/node_modules/@noodle-borg/knowledge-operations/dist/google-identity.d.ts +15 -0
  81. package/node_modules/@noodle-borg/knowledge-operations/dist/google-identity.d.ts.map +1 -0
  82. package/node_modules/@noodle-borg/knowledge-operations/dist/google-identity.js +50 -0
  83. package/node_modules/@noodle-borg/knowledge-operations/dist/google-identity.js.map +1 -0
  84. package/node_modules/@noodle-borg/knowledge-operations/dist/http.d.ts +16 -0
  85. package/node_modules/@noodle-borg/knowledge-operations/dist/http.d.ts.map +1 -0
  86. package/node_modules/@noodle-borg/knowledge-operations/dist/http.js +18 -0
  87. package/node_modules/@noodle-borg/knowledge-operations/dist/http.js.map +1 -0
  88. package/node_modules/@noodle-borg/knowledge-operations/dist/index.d.ts +18 -0
  89. package/node_modules/@noodle-borg/knowledge-operations/dist/index.d.ts.map +1 -0
  90. package/node_modules/@noodle-borg/knowledge-operations/dist/index.js +18 -0
  91. package/node_modules/@noodle-borg/knowledge-operations/dist/index.js.map +1 -0
  92. package/node_modules/@noodle-borg/knowledge-operations/dist/managed-google.d.ts +29 -0
  93. package/node_modules/@noodle-borg/knowledge-operations/dist/managed-google.d.ts.map +1 -0
  94. package/node_modules/@noodle-borg/knowledge-operations/dist/managed-google.js +53 -0
  95. package/node_modules/@noodle-borg/knowledge-operations/dist/managed-google.js.map +1 -0
  96. package/node_modules/@noodle-borg/knowledge-operations/dist/paths.d.ts +21 -0
  97. package/node_modules/@noodle-borg/knowledge-operations/dist/paths.d.ts.map +1 -0
  98. package/node_modules/@noodle-borg/knowledge-operations/dist/paths.js +28 -0
  99. package/node_modules/@noodle-borg/knowledge-operations/dist/paths.js.map +1 -0
  100. package/node_modules/@noodle-borg/knowledge-operations/dist/publication.d.ts +60 -0
  101. package/node_modules/@noodle-borg/knowledge-operations/dist/publication.d.ts.map +1 -0
  102. package/node_modules/@noodle-borg/knowledge-operations/dist/publication.js +230 -0
  103. package/node_modules/@noodle-borg/knowledge-operations/dist/publication.js.map +1 -0
  104. package/node_modules/@noodle-borg/knowledge-operations/dist/routes.d.ts +38 -0
  105. package/node_modules/@noodle-borg/knowledge-operations/dist/routes.d.ts.map +1 -0
  106. package/node_modules/@noodle-borg/knowledge-operations/dist/routes.js +100 -0
  107. package/node_modules/@noodle-borg/knowledge-operations/dist/routes.js.map +1 -0
  108. package/node_modules/@noodle-borg/knowledge-operations/dist/search-port.d.ts +31 -0
  109. package/node_modules/@noodle-borg/knowledge-operations/dist/search-port.d.ts.map +1 -0
  110. package/node_modules/@noodle-borg/knowledge-operations/dist/search-port.js +36 -0
  111. package/node_modules/@noodle-borg/knowledge-operations/dist/search-port.js.map +1 -0
  112. package/node_modules/@noodle-borg/knowledge-operations/dist/service-wiring.d.ts +56 -0
  113. package/node_modules/@noodle-borg/knowledge-operations/dist/service-wiring.d.ts.map +1 -0
  114. package/node_modules/@noodle-borg/knowledge-operations/dist/service-wiring.js +129 -0
  115. package/node_modules/@noodle-borg/knowledge-operations/dist/service-wiring.js.map +1 -0
  116. package/node_modules/@noodle-borg/knowledge-operations/dist/staging-store.d.ts +38 -0
  117. package/node_modules/@noodle-borg/knowledge-operations/dist/staging-store.d.ts.map +1 -0
  118. package/node_modules/@noodle-borg/knowledge-operations/dist/staging-store.js +77 -0
  119. package/node_modules/@noodle-borg/knowledge-operations/dist/staging-store.js.map +1 -0
  120. package/node_modules/@noodle-borg/knowledge-operations/dist/status-routes.d.ts +28 -0
  121. package/node_modules/@noodle-borg/knowledge-operations/dist/status-routes.d.ts.map +1 -0
  122. package/node_modules/@noodle-borg/knowledge-operations/dist/status-routes.js +66 -0
  123. package/node_modules/@noodle-borg/knowledge-operations/dist/status-routes.js.map +1 -0
  124. package/node_modules/@noodle-borg/knowledge-operations/package.json +34 -0
  125. package/node_modules/@noodle-borg/protocol/dist/context-tool.d.ts.map +1 -1
  126. package/node_modules/@noodle-borg/protocol/dist/context-tool.js +15 -1
  127. package/node_modules/@noodle-borg/protocol/dist/context-tool.js.map +1 -1
  128. package/node_modules/@noodle-borg/protocol/dist/handlers/tools.d.ts.map +1 -1
  129. package/node_modules/@noodle-borg/protocol/dist/handlers/tools.js +22 -1
  130. package/node_modules/@noodle-borg/protocol/dist/handlers/tools.js.map +1 -1
  131. package/node_modules/@noodle-borg/protocol/dist/knowledge-tool.d.ts +28 -0
  132. package/node_modules/@noodle-borg/protocol/dist/knowledge-tool.d.ts.map +1 -0
  133. package/node_modules/@noodle-borg/protocol/dist/knowledge-tool.js +26 -0
  134. package/node_modules/@noodle-borg/protocol/dist/knowledge-tool.js.map +1 -0
  135. package/node_modules/@noodle-borg/protocol/dist/mapping.d.ts +5 -1
  136. package/node_modules/@noodle-borg/protocol/dist/mapping.d.ts.map +1 -1
  137. package/node_modules/@noodle-borg/protocol/dist/mapping.js +12 -1
  138. package/node_modules/@noodle-borg/protocol/dist/mapping.js.map +1 -1
  139. package/node_modules/@noodle-borg/protocol/dist/v2/server.d.ts.map +1 -1
  140. package/node_modules/@noodle-borg/protocol/dist/v2/server.js +23 -2
  141. package/node_modules/@noodle-borg/protocol/dist/v2/server.js.map +1 -1
  142. package/node_modules/@noodle-borg/runtime/dist/execute.d.ts +28 -0
  143. package/node_modules/@noodle-borg/runtime/dist/execute.d.ts.map +1 -1
  144. package/node_modules/@noodle-borg/runtime/dist/execute.js.map +1 -1
  145. package/node_modules/@noodle-borg/runtime/dist/index.d.ts +2 -2
  146. package/node_modules/@noodle-borg/runtime/dist/index.d.ts.map +1 -1
  147. package/node_modules/@noodle-borg/runtime/dist/index.js.map +1 -1
  148. package/node_modules/@noodle-borg/runtime/dist/invocation-context.d.ts +12 -0
  149. package/node_modules/@noodle-borg/runtime/dist/invocation-context.d.ts.map +1 -1
  150. package/node_modules/@noodle-borg/service/dist/invocation-context.d.ts +2 -1
  151. package/node_modules/@noodle-borg/service/dist/invocation-context.d.ts.map +1 -1
  152. package/node_modules/@noodle-borg/service/dist/invocation-context.js +19 -6
  153. package/node_modules/@noodle-borg/service/dist/invocation-context.js.map +1 -1
  154. package/node_modules/@noodle-borg/service/dist/options.d.ts +3 -0
  155. package/node_modules/@noodle-borg/service/dist/options.d.ts.map +1 -1
  156. package/node_modules/@noodle-borg/service/dist/registry-compile.d.ts +2 -0
  157. package/node_modules/@noodle-borg/service/dist/registry-compile.d.ts.map +1 -1
  158. package/node_modules/@noodle-borg/service/dist/registry-compile.js +6 -0
  159. package/node_modules/@noodle-borg/service/dist/registry-compile.js.map +1 -1
  160. package/node_modules/@noodle-borg/service/dist/registry-recover.d.ts +26 -0
  161. package/node_modules/@noodle-borg/service/dist/registry-recover.d.ts.map +1 -0
  162. package/node_modules/@noodle-borg/service/dist/registry-recover.js +58 -0
  163. package/node_modules/@noodle-borg/service/dist/registry-recover.js.map +1 -0
  164. package/node_modules/@noodle-borg/service/dist/registry-rollback.d.ts +10 -0
  165. package/node_modules/@noodle-borg/service/dist/registry-rollback.d.ts.map +1 -1
  166. package/node_modules/@noodle-borg/service/dist/registry-rollback.js +25 -0
  167. package/node_modules/@noodle-borg/service/dist/registry-rollback.js.map +1 -1
  168. package/node_modules/@noodle-borg/service/dist/registry.d.ts +5 -0
  169. package/node_modules/@noodle-borg/service/dist/registry.d.ts.map +1 -1
  170. package/node_modules/@noodle-borg/service/dist/registry.js +36 -78
  171. package/node_modules/@noodle-borg/service/dist/registry.js.map +1 -1
  172. package/node_modules/@noodle-borg/service/dist/routes/assistant-agent.d.ts.map +1 -1
  173. package/node_modules/@noodle-borg/service/dist/routes/assistant-agent.js +38 -14
  174. package/node_modules/@noodle-borg/service/dist/routes/assistant-agent.js.map +1 -1
  175. package/node_modules/@noodle-borg/service/dist/routes/assistant-interaction-replay.d.ts.map +1 -1
  176. package/node_modules/@noodle-borg/service/dist/routes/assistant-interaction-replay.js +1 -1
  177. package/node_modules/@noodle-borg/service/dist/routes/assistant-interaction-replay.js.map +1 -1
  178. package/node_modules/@noodle-borg/service/dist/routes/assistant-interaction-stream.d.ts.map +1 -1
  179. package/node_modules/@noodle-borg/service/dist/routes/assistant-interaction-stream.js +1 -1
  180. package/node_modules/@noodle-borg/service/dist/routes/assistant-interaction-stream.js.map +1 -1
  181. package/node_modules/@noodle-borg/service/dist/routes/assistant-interactions.d.ts.map +1 -1
  182. package/node_modules/@noodle-borg/service/dist/routes/assistant-interactions.js +1 -3
  183. package/node_modules/@noodle-borg/service/dist/routes/assistant-interactions.js.map +1 -1
  184. package/node_modules/@noodle-borg/service/dist/routes/assistant-knowledge.d.ts +32 -0
  185. package/node_modules/@noodle-borg/service/dist/routes/assistant-knowledge.d.ts.map +1 -0
  186. package/node_modules/@noodle-borg/service/dist/routes/assistant-knowledge.js +42 -0
  187. package/node_modules/@noodle-borg/service/dist/routes/assistant-knowledge.js.map +1 -0
  188. package/node_modules/@noodle-borg/service/dist/routes/assistant.d.ts.map +1 -1
  189. package/node_modules/@noodle-borg/service/dist/routes/assistant.js +11 -3
  190. package/node_modules/@noodle-borg/service/dist/routes/assistant.js.map +1 -1
  191. package/node_modules/@noodle-borg/service/dist/serve.d.ts.map +1 -1
  192. package/node_modules/@noodle-borg/service/dist/serve.js +4 -0
  193. package/node_modules/@noodle-borg/service/dist/serve.js.map +1 -1
  194. package/node_modules/@noodle-borg/service/dist/service.d.ts.map +1 -1
  195. package/node_modules/@noodle-borg/service/dist/service.js +11 -1
  196. package/node_modules/@noodle-borg/service/dist/service.js.map +1 -1
  197. package/node_modules/@noodle-borg/service/package.json +3 -1
  198. package/node_modules/@noodle-borg/transport-http/dist/handler.d.ts +13 -0
  199. package/node_modules/@noodle-borg/transport-http/dist/handler.d.ts.map +1 -1
  200. package/node_modules/@noodle-borg/transport-http/dist/handler.js.map +1 -1
  201. package/node_modules/@noodle-borg/transport-http/dist/index.d.ts +1 -1
  202. package/node_modules/@noodle-borg/transport-http/dist/index.d.ts.map +1 -1
  203. package/node_modules/@noodle-borg/transport-http/dist/index.js.map +1 -1
  204. package/node_modules/@noodle-borg/transport-http/dist/invocation-client-hints.d.ts +7 -0
  205. package/node_modules/@noodle-borg/transport-http/dist/invocation-client-hints.d.ts.map +1 -0
  206. package/node_modules/@noodle-borg/transport-http/dist/invocation-client-hints.js +86 -0
  207. package/node_modules/@noodle-borg/transport-http/dist/invocation-client-hints.js.map +1 -0
  208. package/node_modules/@noodle-borg/transport-http/dist/serve-request.d.ts.map +1 -1
  209. package/node_modules/@noodle-borg/transport-http/dist/serve-request.js +3 -0
  210. package/node_modules/@noodle-borg/transport-http/dist/serve-request.js.map +1 -1
  211. package/node_modules/@noodle-borg/wire-contracts/dist/index.d.ts +1 -0
  212. package/node_modules/@noodle-borg/wire-contracts/dist/index.d.ts.map +1 -1
  213. package/node_modules/@noodle-borg/wire-contracts/dist/index.js +1 -0
  214. package/node_modules/@noodle-borg/wire-contracts/dist/index.js.map +1 -1
  215. package/node_modules/@noodle-borg/wire-contracts/dist/knowledge.d.ts +134 -0
  216. package/node_modules/@noodle-borg/wire-contracts/dist/knowledge.d.ts.map +1 -0
  217. package/node_modules/@noodle-borg/wire-contracts/dist/knowledge.js +101 -0
  218. package/node_modules/@noodle-borg/wire-contracts/dist/knowledge.js.map +1 -0
  219. package/node_modules/@noodle-borg/wire-contracts/package.json +1 -0
  220. package/node_modules/@noodleseed/assistant/package.json +1 -1
  221. package/package.json +7 -2
  222. /package/node_modules/@noodle-borg/{service → assistant-gateway}/dist/assistant-interactive.js +0 -0
  223. /package/node_modules/@noodle-borg/{service → assistant-gateway}/dist/assistant-presentation.d.ts +0 -0
  224. /package/{dist → node_modules/@noodle-borg/deploy-client/dist}/deploy-payload-size.d.ts +0 -0
  225. /package/{dist → node_modules/@noodle-borg/deploy-client/dist}/deploy-payload-size.d.ts.map +0 -0
  226. /package/{dist → node_modules/@noodle-borg/deploy-client/dist}/deploy-payload-size.js +0 -0
  227. /package/{dist → node_modules/@noodle-borg/deploy-client/dist}/deploy-payload-size.js.map +0 -0
  228. /package/{dist → node_modules/@noodle-borg/deploy-client/dist}/deploy-version.d.ts +0 -0
  229. /package/{dist → node_modules/@noodle-borg/deploy-client/dist}/deploy-version.d.ts.map +0 -0
  230. /package/{dist → node_modules/@noodle-borg/deploy-client/dist}/deploy-version.js +0 -0
  231. /package/{dist → node_modules/@noodle-borg/deploy-client/dist}/deploy-version.js.map +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"publication.js","sourceRoot":"","sources":["../src/publication.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EACL,kBAAkB,EAElB,oBAAoB,EACpB,yBAAyB,EACzB,cAAc,GAMf,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAA2B,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AASlG,oFAAoF;AACpF,MAAM,OAAO,yBAA0B,SAAQ,KAAK;IACzC,MAAM,CAAoC;IAEnD,YAAY,MAAyC;QACnD,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,OAAO,IAAI,8BAA8B,CAAC,CAAC;QAC5D,IAAI,CAAC,IAAI,GAAG,2BAA2B,CAAC;QACxC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF;AAqCD,6FAA6F;AAC7F,MAAM,sBAAsB,GAAG,KAAK,CAAC;AACrC,mEAAmE;AACnE,MAAM,iBAAiB,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAEzC,MAAM,UAAU,0BAA0B,CACxC,MAA8B,EAC9B,OAKC;IAED,MAAM,KAAK,GAAG,IAAI,kBAAkB,EAAE,CAAC;IACvC,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,IAAI,yBAAyB,CAAC;IACxD,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC;IA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D,MAAM,IAAI,GAAG,MAAM,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,YAAY,EAAE,UAAU,CAAC,CAAC;IACnE,IAAI,CAAC;QACH,MAAM,KAAK,CAAC,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;QACzC,MAAM,MAAM,GAAG,MAAM,OAAO,EAAE,CAAC;QAC/B,KAAK,KAAK,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;QAC1C,OAAO,MAAM,CAAC;IAChB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,KAAK,CAAC,UAAU,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;QAClE,MAAM,KAAK,CAAC;IACd,CAAC;YAAS,CAAC;QACT,MAAM,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC3B,CAAC;AACH,CAAC"}
@@ -0,0 +1,38 @@
1
+ import type { IncomingMessage, ServerResponse } from 'node:http';
2
+ import { type DocumentTextCodec, type KnowledgeScope } from '@noodle-borg/knowledge';
3
+ import type { KnowledgeStagingStore } from './staging-store.js';
4
+ export interface KnowledgeTenantRef {
5
+ readonly org: string;
6
+ readonly app: string;
7
+ readonly env: string;
8
+ }
9
+ export interface KnowledgeRouteDeps {
10
+ readonly staging: KnowledgeStagingStore;
11
+ /** Managed-config feature gate (`NOODLE_KNOWLEDGE_ENABLED`), resolved org → app → env. */
12
+ readonly knowledgeEnabled: (tenant: KnowledgeTenantRef) => Promise<boolean>;
13
+ /** Whole-set content-hash reuse: an unchanged component needs no uploads at all. */
14
+ readonly findRevisionByContentHash: (scope: KnowledgeScope, componentName: string, contentHash: string) => Promise<{
15
+ readonly revisionId: string;
16
+ } | undefined>;
17
+ readonly maxBodyBytes: number;
18
+ /** Seals staged bytes at rest; the service injects its secret-box codec. */
19
+ readonly codec?: DocumentTextCodec;
20
+ /** Operator read surface (list/status); wired by `wireKnowledge`, absent in bare handlers. */
21
+ readonly status?: import('./status-routes.js').KnowledgeStatusDeps;
22
+ }
23
+ export declare function knowledgeTenantKey(tenant: KnowledgeTenantRef): string;
24
+ /** The one command that turns the feature on for a tenant; every fail-closed error names it. */
25
+ export declare function knowledgeEnableCommand(tenant: KnowledgeTenantRef): string;
26
+ /**
27
+ * `POST /v1/orgs/{o}/apps/{a}/envs/{e}/knowledge/preflight` — diff declared document hashes
28
+ * against transient staging and published revisions; respond with exactly the hashes that
29
+ * still need bytes. Descriptors only; no contents cross this route.
30
+ */
31
+ export declare function handleKnowledgePreflight(req: IncomingMessage, res: ServerResponse, tenant: KnowledgeTenantRef, deps: KnowledgeRouteDeps): Promise<void>;
32
+ /**
33
+ * `PUT /v1/orgs/{o}/apps/{a}/envs/{e}/knowledge/documents/{sha256}` — raw UTF-8 bytes,
34
+ * verified against the addressed hash before sealing into transient staging (ADR 0202 D5:
35
+ * the service verifies declared length and hash before publication).
36
+ */
37
+ export declare function handleKnowledgeDocumentUpload(req: IncomingMessage, res: ServerResponse, tenant: KnowledgeTenantRef, sha256: string, deps: KnowledgeRouteDeps): Promise<void>;
38
+ //# sourceMappingURL=routes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../src/routes.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AACjE,OAAO,EACL,KAAK,iBAAiB,EAGtB,KAAK,cAAc,EACpB,MAAM,wBAAwB,CAAC;AAQhC,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAEhE,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,OAAO,EAAE,qBAAqB,CAAC;IACxC,0FAA0F;IAC1F,QAAQ,CAAC,gBAAgB,EAAE,CAAC,MAAM,EAAE,kBAAkB,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IAC5E,oFAAoF;IACpF,QAAQ,CAAC,yBAAyB,EAAE,CAClC,KAAK,EAAE,cAAc,EACrB,aAAa,EAAE,MAAM,EACrB,WAAW,EAAE,MAAM,KAChB,OAAO,CAAC;QAAE,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS,CAAC,CAAC;IAC1D,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,4EAA4E;IAC5E,QAAQ,CAAC,KAAK,CAAC,EAAE,iBAAiB,CAAC;IACnC,8FAA8F;IAC9F,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,oBAAoB,EAAE,mBAAmB,CAAC;CACpE;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,kBAAkB,GAAG,MAAM,CAErE;AAED,gGAAgG;AAChG,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,kBAAkB,GAAG,MAAM,CAKzE;AAYD;;;;GAIG;AACH,wBAAsB,wBAAwB,CAC5C,GAAG,EAAE,eAAe,EACpB,GAAG,EAAE,cAAc,EACnB,MAAM,EAAE,kBAAkB,EAC1B,IAAI,EAAE,kBAAkB,GACvB,OAAO,CAAC,IAAI,CAAC,CAsCf;AAED;;;;GAIG;AACH,wBAAsB,6BAA6B,CACjD,GAAG,EAAE,eAAe,EACpB,GAAG,EAAE,cAAc,EACnB,MAAM,EAAE,kBAAkB,EAC1B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,kBAAkB,GACvB,OAAO,CAAC,IAAI,CAAC,CA0Bf"}
@@ -0,0 +1,100 @@
1
+ /**
2
+ * Knowledge control-plane route handlers (ADR 0202 as amended). The service dispatch
3
+ * authorizes the request and parses the tenant path, then delegates here; these handlers own
4
+ * validation, the feature gate, staging, and wire shapes — never auth.
5
+ */
6
+ import { createHash } from 'node:crypto';
7
+ import { documentsContentHash, identityDocumentTextCodec, } from '@noodle-borg/knowledge';
8
+ import { MAX_DOCUMENT_BYTES } from '@noodle-borg/knowledge/limits';
9
+ import { knowledgePreflightRequestSchema, } from '@noodle-borg/wire-contracts';
10
+ import { readBody, sendJson } from './http.js';
11
+ export function knowledgeTenantKey(tenant) {
12
+ return `${tenant.org}/${tenant.app}/${tenant.env}`;
13
+ }
14
+ /** The one command that turns the feature on for a tenant; every fail-closed error names it. */
15
+ export function knowledgeEnableCommand(tenant) {
16
+ return (`noodle variables set NOODLE_KNOWLEDGE_ENABLED --value true --runtime cloud ` +
17
+ `--scope env --org ${tenant.org} --app ${tenant.app} --env ${tenant.env}`);
18
+ }
19
+ function sendGateClosed(res, tenant) {
20
+ sendJson(res, 403, {
21
+ code: 'knowledge_not_enabled',
22
+ error: 'knowledge is not enabled for this org/app/env',
23
+ fix: knowledgeEnableCommand(tenant),
24
+ });
25
+ }
26
+ const SHA256_HEX = /^[0-9a-f]{64}$/;
27
+ /**
28
+ * `POST /v1/orgs/{o}/apps/{a}/envs/{e}/knowledge/preflight` — diff declared document hashes
29
+ * against transient staging and published revisions; respond with exactly the hashes that
30
+ * still need bytes. Descriptors only; no contents cross this route.
31
+ */
32
+ export async function handleKnowledgePreflight(req, res, tenant, deps) {
33
+ if (!(await deps.knowledgeEnabled(tenant)))
34
+ return sendGateClosed(res, tenant);
35
+ const body = await readBody(req, deps.maxBodyBytes);
36
+ if (!body.ok)
37
+ return sendJson(res, body.status, { error: body.error });
38
+ let request;
39
+ try {
40
+ const parsed = knowledgePreflightRequestSchema.safeParse(JSON.parse(body.body.toString('utf8')));
41
+ if (!parsed.success)
42
+ throw new Error(parsed.error.issues[0]?.message ?? 'invalid request');
43
+ request = parsed.data;
44
+ }
45
+ catch (error) {
46
+ return sendJson(res, 400, {
47
+ code: 'invalid_knowledge_request',
48
+ error: `invalid knowledge preflight request: ${error.message}`,
49
+ });
50
+ }
51
+ const tenantKey = knowledgeTenantKey(tenant);
52
+ const scope = { org: tenant.org, app: tenant.app, env: tenant.env };
53
+ const missing = [];
54
+ const seen = new Set();
55
+ for (const component of request.components) {
56
+ const hashes = component.documents.map((document) => document.sha256);
57
+ const published = await deps.findRevisionByContentHash(scope, component.name, documentsContentHash(hashes));
58
+ if (published !== undefined)
59
+ continue;
60
+ for (const sha256 of hashes) {
61
+ if (seen.has(sha256))
62
+ continue;
63
+ seen.add(sha256);
64
+ if (!(await deps.staging.has(tenantKey, sha256)))
65
+ missing.push(sha256);
66
+ }
67
+ }
68
+ const response = { ok: true, missing };
69
+ return sendJson(res, 200, response);
70
+ }
71
+ /**
72
+ * `PUT /v1/orgs/{o}/apps/{a}/envs/{e}/knowledge/documents/{sha256}` — raw UTF-8 bytes,
73
+ * verified against the addressed hash before sealing into transient staging (ADR 0202 D5:
74
+ * the service verifies declared length and hash before publication).
75
+ */
76
+ export async function handleKnowledgeDocumentUpload(req, res, tenant, sha256, deps) {
77
+ if (!(await deps.knowledgeEnabled(tenant)))
78
+ return sendGateClosed(res, tenant);
79
+ if (!SHA256_HEX.test(sha256)) {
80
+ return sendJson(res, 400, {
81
+ code: 'invalid_knowledge_request',
82
+ error: 'document address must be a lowercase hex sha256',
83
+ });
84
+ }
85
+ const body = await readBody(req, Math.min(deps.maxBodyBytes, MAX_DOCUMENT_BYTES));
86
+ if (!body.ok)
87
+ return sendJson(res, body.status, { error: body.error });
88
+ const actual = createHash('sha256').update(body.body).digest('hex');
89
+ if (actual !== sha256) {
90
+ return sendJson(res, 400, {
91
+ code: 'knowledge_document_hash_mismatch',
92
+ error: 'uploaded bytes do not match the addressed content hash',
93
+ });
94
+ }
95
+ const codec = deps.codec ?? identityDocumentTextCodec;
96
+ await deps.staging.put(knowledgeTenantKey(tenant), sha256, await codec.seal(body.body), body.body.length);
97
+ const response = { ok: true, sha256 };
98
+ return sendJson(res, 200, response);
99
+ }
100
+ //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AC,IAAI,CAAC,YAAY,EAAE,kBAAkB,CAAC,CAAC,CAAC;IAClF,IAAI,CAAC,IAAI,CAAC,EAAE;QAAE,OAAO,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC;IACvE,MAAM,MAAM,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACpE,IAAI,MAAM,KAAK,MAAM,EAAE,CAAC;QACtB,OAAO,QAAQ,CAAC,GAAG,EAAE,GAAG,EAAE;YACxB,IAAI,EAAE,kCAAkC;YACxC,KAAK,EAAE,wDAAwD;SAChE,CAAC,CAAC;IACL,CAAC;IACD,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,yBAAyB,CAAC;IACtD,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,CACpB,kBAAkB,CAAC,MAAM,CAAC,EAC1B,MAAM,EACN,MAAM,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,EAC3B,IAAI,CAAC,IAAI,CAAC,MAAM,CACjB,CAAC;IACF,MAAM,QAAQ,GAA4B,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;IAC/D,OAAO,QAAQ,CAAC,GAAG,EAAE,GAAG,EAAE,QAAQ,CAAC,CAAC;AACtC,CAAC"}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Adapts the knowledge search executor to the runtime's deployment-bound port shape
3
+ * (structurally typed against `@noodle-borg/runtime`'s `KnowledgeSearchPort`): tenant and
4
+ * component set are bound once per deployment; failures become typed refusals, never partial
5
+ * answers, and no provider detail crosses the port.
6
+ */
7
+ import { type SearchHit } from '@noodle-borg/knowledge';
8
+ import type { KnowledgeSearchComponent, KnowledgeSearchExecutor } from './executor.js';
9
+ import type { KnowledgeTenantRef } from './routes.js';
10
+ export interface BoundKnowledgeSearchPort {
11
+ enabled(): Promise<boolean>;
12
+ search(componentName: string, request: {
13
+ readonly query: string;
14
+ readonly limit?: number;
15
+ }): Promise<{
16
+ readonly ok: true;
17
+ readonly hits: readonly SearchHit[];
18
+ } | {
19
+ readonly ok: false;
20
+ readonly reason: 'budget_exhausted' | 'not_enabled' | 'provider_error';
21
+ readonly message: string;
22
+ }>;
23
+ }
24
+ export type KnowledgeSearchPortFactory = (tenant: {
25
+ readonly org: string;
26
+ readonly app: string;
27
+ readonly env: string;
28
+ }, components: readonly KnowledgeSearchComponent[]) => BoundKnowledgeSearchPort;
29
+ export declare function knowledgeSearchPortFactory(executor: KnowledgeSearchExecutor): KnowledgeSearchPortFactory;
30
+ export declare function bindKnowledgeSearchPort(executor: KnowledgeSearchExecutor, tenant: KnowledgeTenantRef, components: readonly KnowledgeSearchComponent[]): BoundKnowledgeSearchPort;
31
+ //# sourceMappingURL=search-port.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"search-port.d.ts","sourceRoot":"","sources":["../src/search-port.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAA8C,KAAK,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACpG,OAAO,KAAK,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AACvF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEtD,MAAM,WAAW,wBAAwB;IACvC,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IAC5B,MAAM,CACJ,aAAa,EAAE,MAAM,EACrB,OAAO,EAAE;QAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,GAC3D,OAAO,CACN;QAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;QAAC,QAAQ,CAAC,IAAI,EAAE,SAAS,SAAS,EAAE,CAAA;KAAE,GAC1D;QACE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;QACnB,QAAQ,CAAC,MAAM,EAAE,kBAAkB,GAAG,aAAa,GAAG,gBAAgB,CAAC;QACvE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;KAC1B,CACJ,CAAC;CACH;AAED,MAAM,MAAM,0BAA0B,GAAG,CACvC,MAAM,EAAE;IAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;CAAE,EAC5E,UAAU,EAAE,SAAS,wBAAwB,EAAE,KAC5C,wBAAwB,CAAC;AAE9B,wBAAgB,0BAA0B,CACxC,QAAQ,EAAE,uBAAuB,GAChC,0BAA0B,CAE5B;AAED,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,uBAAuB,EACjC,MAAM,EAAE,kBAAkB,EAC1B,UAAU,EAAE,SAAS,wBAAwB,EAAE,GAC9C,wBAAwB,CAuB1B"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Adapts the knowledge search executor to the runtime's deployment-bound port shape
3
+ * (structurally typed against `@noodle-borg/runtime`'s `KnowledgeSearchPort`): tenant and
4
+ * component set are bound once per deployment; failures become typed refusals, never partial
5
+ * answers, and no provider detail crosses the port.
6
+ */
7
+ import { KnowledgeError, SearchBudgetExhaustedError } from '@noodle-borg/knowledge';
8
+ export function knowledgeSearchPortFactory(executor) {
9
+ return (tenant, components) => bindKnowledgeSearchPort(executor, tenant, components);
10
+ }
11
+ export function bindKnowledgeSearchPort(executor, tenant, components) {
12
+ return {
13
+ enabled: () => executor.enabled(tenant),
14
+ async search(componentName, request) {
15
+ const component = components.find((candidate) => candidate.name === componentName);
16
+ if (component === undefined) {
17
+ return { ok: false, reason: 'provider_error', message: 'unknown knowledge component' };
18
+ }
19
+ try {
20
+ const hits = await executor.search(tenant, component, request);
21
+ return { ok: true, hits };
22
+ }
23
+ catch (error) {
24
+ if (error instanceof SearchBudgetExhaustedError) {
25
+ return { ok: false, reason: 'budget_exhausted', message: error.message };
26
+ }
27
+ if (error instanceof KnowledgeError) {
28
+ const reason = error.layer === 'request' ? 'not_enabled' : 'provider_error';
29
+ return { ok: false, reason, message: error.message };
30
+ }
31
+ return { ok: false, reason: 'provider_error', message: 'knowledge search failed' };
32
+ }
33
+ },
34
+ };
35
+ }
36
+ //# sourceMappingURL=search-port.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"search-port.js","sourceRoot":"","sources":["../src/search-port.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,cAAc,EAAE,0BAA0B,EAAkB,MAAM,wBAAwB,CAAC;AAwBpG,MAAM,UAAU,0BAA0B,CACxC,QAAiC;IAEjC,OAAO,CAAC,MAAM,EAAE,UAAU,EAAE,EAAE,CAAC,uBAAuB,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC;AACvF,CAAC;AAED,MAAM,UAAU,uBAAuB,CACrC,QAAiC,EACjC,MAA0B,EAC1B,UAA+C;IAE/C,OAAO;QACL,OAAO,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC;QACvC,KAAK,CAAC,MAAM,CAAC,aAAa,EAAE,OAAO;YACjC,MAAM,SAAS,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,KAAK,aAAa,CAAC,CAAC;YACnF,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;gBAC5B,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,gBAAgB,EAAE,OAAO,EAAE,6BAA6B,EAAE,CAAC;YACzF,CAAC;YACD,IAAI,CAAC;gBACH,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;gBAC/D,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;YAC5B,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,IAAI,KAAK,YAAY,0BAA0B,EAAE,CAAC;oBAChD,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,kBAAkB,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC;gBAC3E,CAAC;gBACD,IAAI,KAAK,YAAY,cAAc,EAAE,CAAC;oBACpC,MAAM,MAAM,GAAG,KAAK,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,gBAAgB,CAAC;oBAC5E,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC;gBACvD,CAAC;gBACD,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,gBAAgB,EAAE,OAAO,EAAE,yBAAyB,EAAE,CAAC;YACrF,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Composition helpers the service calls from its (size-pinned) bootstrap files, so the thin
3
+ * dispatch stays thin: store construction, schema setup, and route-deps assembly live here.
4
+ */
5
+ import { type CompiledKnowledgeComponent, type DocumentTextCodec, type KnowledgeRevisionStore, type SearchBudgetCeilings, type SearchBudgetStore } from '@noodle-borg/knowledge';
6
+ import type { Pool } from 'pg';
7
+ import { type StringSecretBox } from './codec.js';
8
+ import { type KnowledgeSearchExecutor } from './executor.js';
9
+ import { type ManagedGoogleKnowledge } from './managed-google.js';
10
+ import { type KnowledgeDeployHooks } from './publication.js';
11
+ import type { KnowledgeRouteDeps, KnowledgeTenantRef } from './routes.js';
12
+ import { type KnowledgeSearchPortFactory } from './search-port.js';
13
+ import { type KnowledgeStagingStore } from './staging-store.js';
14
+ export interface KnowledgeServiceStores {
15
+ readonly staging: KnowledgeStagingStore;
16
+ readonly revisionStore: KnowledgeRevisionStore;
17
+ readonly codec?: DocumentTextCodec;
18
+ /** Org-pooled monthly site-search spend control (per-app sub-caps). */
19
+ readonly budgetStore?: SearchBudgetStore;
20
+ /** Managed Noodle-owned Google project; absent means the sites tier is dark. */
21
+ readonly google?: ManagedGoogleKnowledge;
22
+ }
23
+ /** In-memory stores with the identity codec — the no-persistence service default. */
24
+ export declare function defaultKnowledgeStores(): KnowledgeServiceStores;
25
+ /** Durable stores sharing the service's Postgres pool and secret-box custody. */
26
+ export declare function createPostgresKnowledgeStores(pool: Pool, secretBox?: StringSecretBox, env?: NodeJS.ProcessEnv): Promise<KnowledgeServiceStores>;
27
+ /** Budget ceilings from managed config with the ratified v0 defaults (2000 org / 1000 app). */
28
+ export declare function budgetCeilingsResolver(resolveVariables: (tenant: KnowledgeTenantRef) => Promise<Record<string, string>>): (tenant: KnowledgeTenantRef) => Promise<SearchBudgetCeilings>;
29
+ /** Assemble route deps over the service's managed-config resolver (`NOODLE_KNOWLEDGE_ENABLED`). */
30
+ export declare function buildKnowledgeRouteDeps(stores: KnowledgeServiceStores, resolveVariables: (tenant: KnowledgeTenantRef) => Promise<Record<string, string>>, maxBodyBytes: number): KnowledgeRouteDeps;
31
+ /**
32
+ * One-call composition for the service: resolve stores, build route deps, and register the
33
+ * deploy-coupled publication hooks on the registry (structurally typed; no service import).
34
+ */
35
+ export declare function wireKnowledge(registry: {
36
+ setKnowledgeDeployHooks(hooks: KnowledgeDeployHooks, search?: KnowledgeSearchPortFactory): void;
37
+ getActiveByTenant(ref: {
38
+ org: string;
39
+ app: string;
40
+ env: string;
41
+ }): Promise<{
42
+ readonly served: {
43
+ readonly artifact: {
44
+ readonly server: ActiveServerKnowledge;
45
+ };
46
+ };
47
+ } | undefined>;
48
+ }, stores: KnowledgeServiceStores | undefined, resolveVariables: (tenant: KnowledgeTenantRef) => Promise<Record<string, string>>, maxBodyBytes: number): KnowledgeRouteDeps & {
49
+ readonly executor: KnowledgeSearchExecutor;
50
+ };
51
+ interface ActiveServerKnowledge {
52
+ readonly knowledge?: readonly CompiledKnowledgeComponent[] | undefined;
53
+ readonly deploymentId?: string | undefined;
54
+ }
55
+ export {};
56
+ //# sourceMappingURL=service-wiring.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service-wiring.d.ts","sourceRoot":"","sources":["../src/service-wiring.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EACL,KAAK,0BAA0B,EAC/B,KAAK,iBAAiB,EAGtB,KAAK,sBAAsB,EAG3B,KAAK,oBAAoB,EACzB,KAAK,iBAAiB,EACvB,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAC/B,OAAO,EAAE,KAAK,eAAe,EAA0B,MAAM,YAAY,CAAC;AAC1E,OAAO,EAAiC,KAAK,uBAAuB,EAAE,MAAM,eAAe,CAAC;AAC5F,OAAO,EACL,KAAK,sBAAsB,EAI5B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAA8B,KAAK,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AACzF,OAAO,KAAK,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAC1E,OAAO,EAAE,KAAK,0BAA0B,EAA8B,MAAM,kBAAkB,CAAC;AAC/F,OAAO,EAEL,KAAK,qBAAqB,EAE3B,MAAM,oBAAoB,CAAC;AAG5B,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,OAAO,EAAE,qBAAqB,CAAC;IACxC,QAAQ,CAAC,aAAa,EAAE,sBAAsB,CAAC;IAC/C,QAAQ,CAAC,KAAK,CAAC,EAAE,iBAAiB,CAAC;IACnC,uEAAuE;IACvE,QAAQ,CAAC,WAAW,CAAC,EAAE,iBAAiB,CAAC;IACzC,gFAAgF;IAChF,QAAQ,CAAC,MAAM,CAAC,EAAE,sBAAsB,CAAC;CAC1C;AAED,qFAAqF;AACrF,wBAAgB,sBAAsB,IAAI,sB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AE,MAAM,GACnB,kBAAkB,GAAG;IAAE,QAAQ,CAAC,QAAQ,EAAE,uBAAuB,CAAA;CAAE,CAmErE;AAED,UAAU,qBAAqB;IAC7B,QAAQ,CAAC,SAAS,CAAC,EAAE,SAAS,0BAA0B,EAAE,GAAG,SAAS,CAAC;IACvE,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC5C"}
@@ -0,0 +1,129 @@
1
+ /**
2
+ * Composition helpers the service calls from its (size-pinned) bootstrap files, so the thin
3
+ * dispatch stays thin: store construction, schema setup, and route-deps assembly live here.
4
+ */
5
+ import { InMemoryKnowledgeRevisionStore, InMemorySearchBudgetStore, PostgresKnowledgeRevisionStore, PostgresSearchBudgetStore, } from '@noodle-borg/knowledge';
6
+ import { secretBoxDocumentCodec } from './codec.js';
7
+ import { createKnowledgeSearchExecutor } from './executor.js';
8
+ import { managedGoogleFromEnv, managedSiteProvisioned, managedSiteSearchFor, } from './managed-google.js';
9
+ import { createKnowledgeDeployHooks } from './publication.js';
10
+ import { knowledgeSearchPortFactory } from './search-port.js';
11
+ import { InMemoryKnowledgeStagingStore, PostgresKnowledgeStagingStore, } from './staging-store.js';
12
+ /** In-memory stores with the identity codec — the no-persistence service default. */
13
+ export function defaultKnowledgeStores() {
14
+ return {
15
+ staging: new InMemoryKnowledgeStagingStore(),
16
+ revisionStore: new InMemoryKnowledgeRevisionStore(),
17
+ budgetStore: new InMemorySearchBudgetStore(),
18
+ };
19
+ }
20
+ /** Durable stores sharing the service's Postgres pool and secret-box custody. */
21
+ export async function createPostgresKnowledgeStores(pool, secretBox, env = process.env) {
22
+ const codec = secretBox === undefined ? undefined : secretBoxDocumentCodec(secretBox);
23
+ const staging = new PostgresKnowledgeStagingStore(pool);
24
+ const revisionStore = new PostgresKnowledgeRevisionStore(pool, codec);
25
+ const budgetStore = new PostgresSearchBudgetStore(pool);
26
+ await staging.ensureSchema();
27
+ await revisionStore.ensureSchema();
28
+ await budgetStore.ensureSchema();
29
+ const google = managedGoogleFromEnv(env);
30
+ return {
31
+ staging,
32
+ revisionStore,
33
+ budgetStore,
34
+ ...(codec === undefined ? {} : { codec }),
35
+ ...(google === undefined ? {} : { google }),
36
+ };
37
+ }
38
+ /** Budget ceilings from managed config with the ratified v0 defaults (2000 org / 1000 app). */
39
+ export function budgetCeilingsResolver(resolveVariables) {
40
+ return async (tenant) => {
41
+ const variables = await resolveVariables(tenant);
42
+ const org = Number(variables.NOODLE_KNOWLEDGE_SEARCH_BUDGET_ORG_MONTHLY ?? '2000');
43
+ const app = Number(variables.NOODLE_KNOWLEDGE_SEARCH_BUDGET_APP_MONTHLY ?? '1000');
44
+ return {
45
+ org: Number.isFinite(org) ? Math.max(0, Math.floor(org)) : 2000,
46
+ app: Number.isFinite(app) ? Math.max(0, Math.floor(app)) : 1000,
47
+ };
48
+ };
49
+ }
50
+ /** Assemble route deps over the service's managed-config resolver (`NOODLE_KNOWLEDGE_ENABLED`). */
51
+ export function buildKnowledgeRouteDeps(stores, resolveVariables, maxBodyBytes) {
52
+ return {
53
+ staging: stores.staging,
54
+ knowledgeEnabled: async (tenant) => (await resolveVariables(tenant)).NOODLE_KNOWLEDGE_ENABLED === 'true',
55
+ findRevisionByContentHash: (scope, componentName, contentHash) => stores.revisionStore.findByContentHash(scope, componentName, contentHash),
56
+ maxBodyBytes,
57
+ ...(stores.codec === undefined ? {} : { codec: stores.codec }),
58
+ };
59
+ }
60
+ /**
61
+ * One-call composition for the service: resolve stores, build route deps, and register the
62
+ * deploy-coupled publication hooks on the registry (structurally typed; no service import).
63
+ */
64
+ export function wireKnowledge(registry, stores, resolveVariables, maxBodyBytes) {
65
+ const resolved = stores ?? defaultKnowledgeStores();
66
+ const deps = buildKnowledgeRouteDeps(resolved, resolveVariables, maxBodyBytes);
67
+ const google = resolved.google;
68
+ const ceilings = budgetCeilingsResolver(resolveVariables);
69
+ const hooks = createKnowledgeDeployHooks(resolved, {
70
+ knowledgeEnabled: deps.knowledgeEnabled,
71
+ ...(google === undefined
72
+ ? {}
73
+ : { siteProvisioned: (tenant) => managedSiteProvisioned(google, tenant) }),
74
+ });
75
+ const executor = createKnowledgeSearchExecutor({
76
+ hooks,
77
+ knowledgeEnabled: deps.knowledgeEnabled,
78
+ ...(resolved.budgetStore === undefined
79
+ ? {}
80
+ : { budget: { store: resolved.budgetStore, ceilings } }),
81
+ ...(google === undefined
82
+ ? {}
83
+ : { siteSearchFor: (tenant) => managedSiteSearchFor(google, tenant) }),
84
+ });
85
+ registry.setKnowledgeDeployHooks(hooks, knowledgeSearchPortFactory(executor));
86
+ const status = {
87
+ revisionStore: resolved.revisionStore,
88
+ knowledgeEnabled: deps.knowledgeEnabled,
89
+ ...(google === undefined
90
+ ? {}
91
+ : {
92
+ siteProvisioningState: async (tenant) => (await managedSiteProvisioned(google, tenant))
93
+ ? 'ready'
94
+ : 'missing',
95
+ }),
96
+ ...(resolved.budgetStore === undefined
97
+ ? {}
98
+ : {
99
+ budget: async (tenant) => {
100
+ const bounds = await ceilings(tenant);
101
+ const state = await resolved.budgetStore?.peek({ org: tenant.org, app: tenant.app }, bounds);
102
+ if (state === undefined)
103
+ return undefined;
104
+ return {
105
+ year: state.year,
106
+ month: state.month,
107
+ orgConsumed: state.orgConsumed,
108
+ appConsumed: state.appConsumed,
109
+ orgCeiling: state.orgCeiling,
110
+ appCeiling: state.appCeiling,
111
+ blocked: state.orgCeiling <= 0 ||
112
+ state.appCeiling <= 0 ||
113
+ state.orgConsumed >= state.orgCeiling ||
114
+ state.appConsumed >= state.appCeiling,
115
+ };
116
+ },
117
+ }),
118
+ activeKnowledge: async (tenant) => {
119
+ const target = await registry.getActiveByTenant(tenant);
120
+ const server = target?.served.artifact.server;
121
+ const components = server?.knowledge;
122
+ if (components === undefined || components.length === 0)
123
+ return undefined;
124
+ return { components, deploymentId: server?.deploymentId ?? '' };
125
+ },
126
+ };
127
+ return { ...deps, status, executor };
128
+ }
129
+ //# sourceMappingURL=service-wiring.js.map
@@ -0,0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;oBAC1C,OAAO;wBACL,IAAI,EAAE,KAAK,CAAC,IAAI;wBAChB,KAAK,EAAE,KAAK,CAAC,KAAK;wBAClB,WAAW,EAAE,KAAK,CAAC,WAAW;wBAC9B,WAAW,EAAE,KAAK,CAAC,WAAW;wBAC9B,UAAU,EAAE,KAAK,CAAC,UAAU;wBAC5B,UAAU,EAAE,KAAK,CAAC,UAAU;wBAC5B,OAAO,EACL,KAAK,CAAC,UAAU,IAAI,CAAC;4BACrB,KAAK,CAAC,UAAU,IAAI,CAAC;4BACrB,KAAK,CAAC,WAAW,IAAI,KAAK,CAAC,UAAU;4BACrC,KAAK,CAAC,WAAW,IAAI,KAAK,CAAC,UAAU;qBACxC,CAAC;gBACJ,CAAC;aACF,CAAC;QACN,eAAe,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE;YAChC,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC;YACxD,MAAM,MAAM,GAAG,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC;YAC9C,MAAM,UAAU,GAAG,MAAM,EAAE,SAAS,CAAC;YACrC,IAAI,UAAU,KAAK,SAAS,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC;gBAAE,OAAO,SAAS,CAAC;YAC1E,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,EAAE,YAAY,IAAI,EAAE,EAAE,CAAC;QAClE,CAAC;KACF,CAAC;IACF,OAAO,EAAE,GAAG,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;AACvC,CAAC"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Encrypted transient document staging (ADR 0202 D5): deploy uploads land here, sealed and
3
+ * content-addressed by tenant + sha256, until the deploy transaction publishes them into a
4
+ * revision. Entries are TTL-bounded — an upload that never publishes is swept, so plaintext
5
+ * never persists outside the sealed revision store.
6
+ */
7
+ import type { Pool } from 'pg';
8
+ /** How long staged bytes may wait for their deploy transaction before being swept. */
9
+ export declare const STAGING_TTL_MS: number;
10
+ export interface KnowledgeStagingStore {
11
+ /** Store sealed bytes. Re-uploading the same tenant+hash is idempotent. */
12
+ put(tenantKey: string, sha256: string, sealed: Buffer, bytes: number): Promise<void>;
13
+ has(tenantKey: string, sha256: string): Promise<boolean>;
14
+ /** Sealed bytes for a staged document, if present and unexpired. */
15
+ get(tenantKey: string, sha256: string): Promise<Buffer | undefined>;
16
+ /** Remove entries older than the TTL. Returns the removed count. */
17
+ sweepExpired(): Promise<number>;
18
+ }
19
+ export declare class InMemoryKnowledgeStagingStore implements KnowledgeStagingStore {
20
+ private readonly entries;
21
+ private readonly now;
22
+ constructor(now?: () => Date);
23
+ put(tenantKey: string, sha256: string, sealed: Buffer): Promise<void>;
24
+ has(tenantKey: string, sha256: string): Promise<boolean>;
25
+ get(tenantKey: string, sha256: string): Promise<Buffer | undefined>;
26
+ sweepExpired(): Promise<number>;
27
+ private key;
28
+ }
29
+ export declare class PostgresKnowledgeStagingStore implements KnowledgeStagingStore {
30
+ #private;
31
+ constructor(pool: Pool, now?: () => Date);
32
+ ensureSchema(): Promise<void>;
33
+ put(tenantKey: string, sha256: string, sealed: Buffer, bytes: number): Promise<void>;
34
+ has(tenantKey: string, sha256: string): Promise<boolean>;
35
+ get(tenantKey: string, sha256: string): Promise<Buffer | undefined>;
36
+ sweepExpired(): Promise<number>;
37
+ }
38
+ //# sourceMappingURL=staging-store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"staging-store.d.ts","sourceRoot":"","sources":["../src/staging-store.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAE/B,sFAAsF;AACtF,eAAO,MAAM,cAAc,QAAiB,CAAC;AAE7C,MAAM,WAAW,qBAAqB;IACpC,2EAA2E;IAC3E,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MA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AG,OAAO,CAAC,OAAO,CAAC;IAIxD,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAUnE,YAAY,IAAI,OAAO,CAAC,MAAM,CAAC;CAQtC"}
@@ -0,0 +1,77 @@
1
+ /** How long staged bytes may wait for their deploy transaction before being swept. */
2
+ export const STAGING_TTL_MS = 60 * 60 * 1000;
3
+ export class InMemoryKnowledgeStagingStore {
4
+ entries = new Map();
5
+ now;
6
+ constructor(now = () => new Date()) {
7
+ this.now = now;
8
+ }
9
+ async put(tenantKey, sha256, sealed) {
10
+ this.entries.set(this.key(tenantKey, sha256), { sealed, stagedAt: this.now().getTime() });
11
+ }
12
+ async has(tenantKey, sha256) {
13
+ return (await this.get(tenantKey, sha256)) !== undefined;
14
+ }
15
+ async get(tenantKey, sha256) {
16
+ const entry = this.entries.get(this.key(tenantKey, sha256));
17
+ if (entry === undefined)
18
+ return undefined;
19
+ if (this.now().getTime() - entry.stagedAt > STAGING_TTL_MS)
20
+ return undefined;
21
+ return entry.sealed;
22
+ }
23
+ async sweepExpired() {
24
+ const cutoff = this.now().getTime() - STAGING_TTL_MS;
25
+ let removed = 0;
26
+ for (const [key, entry] of this.entries) {
27
+ if (entry.stagedAt < cutoff) {
28
+ this.entries.delete(key);
29
+ removed += 1;
30
+ }
31
+ }
32
+ return removed;
33
+ }
34
+ key(tenantKey, sha256) {
35
+ return `${tenantKey}#${sha256}`;
36
+ }
37
+ }
38
+ export class PostgresKnowledgeStagingStore {
39
+ #pool;
40
+ #now;
41
+ constructor(pool, now = () => new Date()) {
42
+ this.#pool = pool;
43
+ this.#now = now;
44
+ }
45
+ async ensureSchema() {
46
+ await this.#pool.query(`
47
+ CREATE TABLE IF NOT EXISTS knowledge_staging_documents (
48
+ tenant_key text NOT NULL,
49
+ sha256 text NOT NULL,
50
+ ciphertext bytea NOT NULL,
51
+ bytes integer NOT NULL,
52
+ staged_at timestamptz NOT NULL,
53
+ PRIMARY KEY (tenant_key, sha256)
54
+ )
55
+ `);
56
+ }
57
+ async put(tenantKey, sha256, sealed, bytes) {
58
+ await this.#pool.query(`INSERT INTO knowledge_staging_documents (tenant_key, sha256, ciphertext, bytes, staged_at)
59
+ VALUES ($1, $2, $3, $4, $5)
60
+ ON CONFLICT (tenant_key, sha256) DO UPDATE SET staged_at = $5`, [tenantKey, sha256, sealed, bytes, this.#now()]);
61
+ }
62
+ async has(tenantKey, sha256) {
63
+ return (await this.get(tenantKey, sha256)) !== undefined;
64
+ }
65
+ async get(tenantKey, sha256) {
66
+ const cutoff = new Date(this.#now().getTime() - STAGING_TTL_MS);
67
+ const result = await this.#pool.query(`SELECT ciphertext FROM knowledge_staging_documents
68
+ WHERE tenant_key = $1 AND sha256 = $2 AND staged_at >= $3`, [tenantKey, sha256, cutoff]);
69
+ return result.rows[0]?.ciphertext;
70
+ }
71
+ async sweepExpired() {
72
+ const cutoff = new Date(this.#now().getTime() - STAGING_TTL_MS);
73
+ const result = await this.#pool.query('DELETE FROM knowledge_staging_documents WHERE staged_at < $1', [cutoff]);
74
+ return result.rowCount ?? 0;
75
+ }
76
+ }
77
+ //# sourceMappingURL=staging-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"staging-store.js","sourceRoot":"","sources":["../src/staging-store.ts"],"names":[],"mappings":"AAQA,sFAAsF;AACtF,MAAM,CAAC,MAAM,cAAc,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAY7C,MAAM,OAAO,6BAA6B;IACvB,OAAO,GAAG,IAAI,GAAG,EAAgD,CAAC;IAClE,GAAG,CAAa;IAEjC,YAAY,MAAkB,GAAG,EAAE,CAAC,IAAI,IAAI,EAAE;QAC5C,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACjB,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,SAAiB,EAAE,MAAc,EAAE,MAAc;QACzD,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC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AG,cAAc,CAAC,CAAC;QAChE,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,KAAK,CACnC,8DAA8D,EAC9D,CAAC,MAAM,CAAC,CACT,CAAC;QACF,OAAO,MAAM,CAAC,QAAQ,IAAI,CAAC,CAAC;IAC9B,CAAC;CACF"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Operator surface (ADR 0202 as amended): `knowledge list` and `knowledge status <name>` are
3
+ * the whole v0 CLI-facing read surface. Responses say "versioned documents" versus "live site"
4
+ * lifecycle truth — active revision, declaring deployment, provisioning state — and never
5
+ * contents, credentials, or raw provider payloads.
6
+ */
7
+ import type { IncomingMessage, ServerResponse } from 'node:http';
8
+ import type { CompiledKnowledgeComponent, KnowledgeRevisionStore } from '@noodle-borg/knowledge';
9
+ import type { KnowledgeBudgetState } from '@noodle-borg/wire-contracts';
10
+ import { type KnowledgeTenantRef } from './routes.js';
11
+ export interface KnowledgeStatusDeps {
12
+ readonly revisionStore: KnowledgeRevisionStore;
13
+ readonly knowledgeEnabled: (tenant: KnowledgeTenantRef) => Promise<boolean>;
14
+ /** The active deployment's compiled knowledge components, or undefined when none is active. */
15
+ readonly activeKnowledge: (tenant: KnowledgeTenantRef) => Promise<{
16
+ readonly components: readonly CompiledKnowledgeComponent[];
17
+ readonly deploymentId: string;
18
+ } | undefined>;
19
+ /** Managed site datastore readiness; absent until the Google slice binds a checker. */
20
+ readonly siteProvisioningState?: (tenant: KnowledgeTenantRef) => Promise<'ready' | 'missing'>;
21
+ /** Current month's search-budget state (the amendment's honest operator-visible counters). */
22
+ readonly budget?: (tenant: KnowledgeTenantRef) => Promise<KnowledgeBudgetState | undefined>;
23
+ }
24
+ /** `GET /v1/orgs/{o}/apps/{a}/envs/{e}/knowledge` */
25
+ export declare function handleKnowledgeList(_req: IncomingMessage, res: ServerResponse, tenant: KnowledgeTenantRef, deps: KnowledgeStatusDeps): Promise<void>;
26
+ /** `GET /v1/orgs/{o}/apps/{a}/envs/{e}/knowledge/{name}/status` */
27
+ export declare function handleKnowledgeStatus(_req: IncomingMessage, res: ServerResponse, tenant: KnowledgeTenantRef, componentName: string, deps: KnowledgeStatusDeps): Promise<void>;
28
+ //# sourceMappingURL=status-routes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"status-routes.d.ts","sourceRoot":"","sources":["../src/status-routes.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AACjE,OAAO,KAAK,EAAE,0BAA0B,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AACjG,OAAO,KAAK,EACV,oBAAoB,EAIrB,MAAM,6BAA6B,CAAC;AAErC,OAAO,EAAE,KAAK,kBAAkB,EAA0B,MAAM,aAAa,CAAC;AAE9E,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,aAAa,EAAE,sBAAsB,CAAC;IAC/C,QAAQ,CAAC,gBAAgB,EAAE,CAAC,MAAM,EAAE,kBAAkB,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IAC5E,+FAA+F;IAC/F,QAAQ,CAAC,eAAe,EAAE,CAAC,MAAM,EAAE,kBAAkB,KAAK,OAAO,CAC7D;QACE,QAAQ,CAAC,UAAU,EAAE,SAAS,0BAA0B,EAAE,CAAC;QAC3D,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;KAC/B,GACD,SAAS,CACZ,CAAC;IACF,uFAAuF;IACvF,QAAQ,CAAC,qBAAqB,CAAC,EAAE,CAAC,MAAM,EAAE,kBAAkB,KAAK,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC,CAAC;IAC9F,8FAA8F;IAC9F,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,kBAAkB,KAAK,OAAO,CAAC,oBAAoB,GAAG,SAAS,CAAC,CAAC;CAC7F;AA8BD,qDAAqD;AACrD,wBAAsB,mBAAmB,CACvC,IAAI,EAAE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