@1mcp/agent 0.35.0-beta.4 → 0.36.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 (262) hide show
  1. package/build/admin/assets/{admin-AboutRuntimeWorkspace-CM2ZafTJ.js → admin-AboutRuntimeWorkspace-DH2QC2nJ.js} +1 -1
  2. package/build/admin/assets/admin-BackendLogsWorkspace-BKavXT9B.js +1 -0
  3. package/build/admin/assets/admin-InstructionTemplatesWorkspace-CvG4EPdZ.js +1 -0
  4. package/build/admin/assets/admin-OAuthServicesWorkspace-BCGj2hP4.js +1 -0
  5. package/build/admin/assets/admin-PresetAuthoringWorkspace-BboJVBFl.js +1 -0
  6. package/build/admin/assets/admin-console-D6jyI73o.css +1 -0
  7. package/build/admin/assets/admin-console-xbgqUjbT.js +3 -0
  8. package/build/admin/assets/admin-icons-CYGTDZA5.js +1 -0
  9. package/build/admin/assets/admin-mantine-xwbfu5Gd.js +53 -0
  10. package/build/admin/index.html +4 -4
  11. package/build/auth/sdkOAuthClientProvider.d.ts +4 -0
  12. package/build/auth/sdkOAuthClientProvider.d.ts.map +1 -1
  13. package/build/auth/sdkOAuthClientProvider.js +29 -0
  14. package/build/auth/sdkOAuthClientProvider.js.map +1 -1
  15. package/build/commands/instructions/instructions.d.ts.map +1 -1
  16. package/build/commands/instructions/instructions.js +56 -1
  17. package/build/commands/instructions/instructions.js.map +1 -1
  18. package/build/commands/mcp/add.js +2 -2
  19. package/build/commands/mcp/add.js.map +1 -1
  20. package/build/commands/mcp/list.js +1 -1
  21. package/build/commands/mcp/list.js.map +1 -1
  22. package/build/commands/mcp/update.js +1 -1
  23. package/build/commands/mcp/update.js.map +1 -1
  24. package/build/commands/shared/serveTargetResolver.d.ts.map +1 -1
  25. package/build/commands/shared/serveTargetResolver.js +17 -22
  26. package/build/commands/shared/serveTargetResolver.js.map +1 -1
  27. package/build/config/configContext.d.ts +2 -0
  28. package/build/config/configContext.d.ts.map +1 -1
  29. package/build/config/configContext.js +5 -0
  30. package/build/config/configContext.js.map +1 -1
  31. package/build/config/configLoader.d.ts +8 -0
  32. package/build/config/configLoader.d.ts.map +1 -1
  33. package/build/config/configLoader.js +35 -11
  34. package/build/config/configLoader.js.map +1 -1
  35. package/build/config/configManager.d.ts +16 -1
  36. package/build/config/configManager.d.ts.map +1 -1
  37. package/build/config/configManager.js +77 -0
  38. package/build/config/configManager.js.map +1 -1
  39. package/build/config/configWatcher.d.ts +2 -0
  40. package/build/config/configWatcher.d.ts.map +1 -1
  41. package/build/config/configWatcher.js +9 -4
  42. package/build/config/configWatcher.js.map +1 -1
  43. package/build/config/configuredServerTargets.d.ts +3 -0
  44. package/build/config/configuredServerTargets.d.ts.map +1 -0
  45. package/build/config/configuredServerTargets.js +8 -0
  46. package/build/config/configuredServerTargets.js.map +1 -0
  47. package/build/config/envProcessor.d.ts +2 -1
  48. package/build/config/envProcessor.d.ts.map +1 -1
  49. package/build/config/envProcessor.js +16 -9
  50. package/build/config/envProcessor.js.map +1 -1
  51. package/build/config/mcpConfigManager.d.ts +3 -0
  52. package/build/config/mcpConfigManager.d.ts.map +1 -1
  53. package/build/config/mcpConfigManager.js +15 -0
  54. package/build/config/mcpConfigManager.js.map +1 -1
  55. package/build/config/runtimeScopeEnv.d.ts +15 -0
  56. package/build/config/runtimeScopeEnv.d.ts.map +1 -0
  57. package/build/config/runtimeScopeEnv.js +231 -0
  58. package/build/config/runtimeScopeEnv.js.map +1 -0
  59. package/build/config/runtimeTargetFingerprint.d.ts +3 -0
  60. package/build/config/runtimeTargetFingerprint.d.ts.map +1 -0
  61. package/build/config/runtimeTargetFingerprint.js +66 -0
  62. package/build/config/runtimeTargetFingerprint.js.map +1 -0
  63. package/build/config/types.d.ts +5 -0
  64. package/build/config/types.d.ts.map +1 -1
  65. package/build/config/types.js +1 -0
  66. package/build/config/types.js.map +1 -1
  67. package/build/constants/api.d.ts +1 -0
  68. package/build/constants/api.d.ts.map +1 -1
  69. package/build/constants/api.js +1 -0
  70. package/build/constants/api.js.map +1 -1
  71. package/build/constants/mcp.d.ts +1 -1
  72. package/build/constants/mcp.d.ts.map +1 -1
  73. package/build/constants/mcp.js +1 -1
  74. package/build/constants/mcp.js.map +1 -1
  75. package/build/core/capabilities/capabilityAggregator.d.ts.map +1 -1
  76. package/build/core/capabilities/capabilityAggregator.js +33 -14
  77. package/build/core/capabilities/capabilityAggregator.js.map +1 -1
  78. package/build/core/capabilities/capabilityCatalog.d.ts +1 -1
  79. package/build/core/capabilities/capabilityCatalog.d.ts.map +1 -1
  80. package/build/core/capabilities/capabilityCatalog.js +19 -7
  81. package/build/core/capabilities/capabilityCatalog.js.map +1 -1
  82. package/build/core/capabilities/capabilityPagination.d.ts.map +1 -1
  83. package/build/core/capabilities/capabilityPagination.js +7 -4
  84. package/build/core/capabilities/capabilityPagination.js.map +1 -1
  85. package/build/core/capabilities/configuredToolSnapshot.d.ts +34 -0
  86. package/build/core/capabilities/configuredToolSnapshot.d.ts.map +1 -0
  87. package/build/core/capabilities/configuredToolSnapshot.js +137 -0
  88. package/build/core/capabilities/configuredToolSnapshot.js.map +1 -0
  89. package/build/core/capabilities/lazyLoadingOrchestrator.d.ts.map +1 -1
  90. package/build/core/capabilities/lazyLoadingOrchestrator.js +8 -4
  91. package/build/core/capabilities/lazyLoadingOrchestrator.js.map +1 -1
  92. package/build/core/capabilities/metaToolProvider.js +3 -3
  93. package/build/core/capabilities/metaToolProvider.js.map +1 -1
  94. package/build/core/client/clientManager.d.ts.map +1 -1
  95. package/build/core/client/clientManager.js +31 -19
  96. package/build/core/client/clientManager.js.map +1 -1
  97. package/build/core/client/connectionHandler.d.ts.map +1 -1
  98. package/build/core/client/connectionHandler.js +9 -6
  99. package/build/core/client/connectionHandler.js.map +1 -1
  100. package/build/core/client/postAuthOAuthRecovery.d.ts +6 -0
  101. package/build/core/client/postAuthOAuthRecovery.d.ts.map +1 -0
  102. package/build/core/client/postAuthOAuthRecovery.js +74 -0
  103. package/build/core/client/postAuthOAuthRecovery.js.map +1 -0
  104. package/build/core/configChangeHandler.d.ts +5 -0
  105. package/build/core/configChangeHandler.d.ts.map +1 -1
  106. package/build/core/configChangeHandler.js +58 -14
  107. package/build/core/configChangeHandler.js.map +1 -1
  108. package/build/core/instructions/effectiveServerInstructions.d.ts +17 -0
  109. package/build/core/instructions/effectiveServerInstructions.d.ts.map +1 -0
  110. package/build/core/instructions/effectiveServerInstructions.js +12 -0
  111. package/build/core/instructions/effectiveServerInstructions.js.map +1 -0
  112. package/build/core/instructions/instructionAggregator.d.ts +51 -2
  113. package/build/core/instructions/instructionAggregator.d.ts.map +1 -1
  114. package/build/core/instructions/instructionAggregator.js +191 -30
  115. package/build/core/instructions/instructionAggregator.js.map +1 -1
  116. package/build/core/instructions/instructionsDistribution.d.ts +53 -0
  117. package/build/core/instructions/instructionsDistribution.d.ts.map +1 -1
  118. package/build/core/instructions/instructionsDistribution.js +25 -0
  119. package/build/core/instructions/instructionsDistribution.js.map +1 -1
  120. package/build/core/instructions/templateTypes.d.ts +25 -3
  121. package/build/core/instructions/templateTypes.d.ts.map +1 -1
  122. package/build/core/instructions/templateTypes.js +45 -0
  123. package/build/core/instructions/templateTypes.js.map +1 -1
  124. package/build/core/loading/mcpLoadingManager.d.ts.map +1 -1
  125. package/build/core/loading/mcpLoadingManager.js +5 -3
  126. package/build/core/loading/mcpLoadingManager.js.map +1 -1
  127. package/build/core/protocol/requestHandlerUtils.d.ts.map +1 -1
  128. package/build/core/protocol/requestHandlerUtils.js +3 -3
  129. package/build/core/protocol/requestHandlerUtils.js.map +1 -1
  130. package/build/core/protocol/toolRequestHandlers.d.ts.map +1 -1
  131. package/build/core/protocol/toolRequestHandlers.js +18 -5
  132. package/build/core/protocol/toolRequestHandlers.js.map +1 -1
  133. package/build/core/server/backendStdioSupervisor.d.ts.map +1 -1
  134. package/build/core/server/backendStdioSupervisor.js +2 -1
  135. package/build/core/server/backendStdioSupervisor.js.map +1 -1
  136. package/build/core/server/clientInstanceFactory.d.ts +2 -1
  137. package/build/core/server/clientInstanceFactory.d.ts.map +1 -1
  138. package/build/core/server/clientInstanceFactory.js +9 -2
  139. package/build/core/server/clientInstanceFactory.js.map +1 -1
  140. package/build/core/server/clientInstancePool.d.ts +1 -0
  141. package/build/core/server/clientInstancePool.d.ts.map +1 -1
  142. package/build/core/server/clientInstancePool.js +92 -55
  143. package/build/core/server/clientInstancePool.js.map +1 -1
  144. package/build/core/server/clientInstancePoolTypes.d.ts +2 -0
  145. package/build/core/server/clientInstancePoolTypes.d.ts.map +1 -1
  146. package/build/core/server/disabledTools.d.ts +2 -0
  147. package/build/core/server/disabledTools.d.ts.map +1 -1
  148. package/build/core/server/disabledTools.js +7 -4
  149. package/build/core/server/disabledTools.js.map +1 -1
  150. package/build/core/server/mcpServerLifecycleManager.d.ts +0 -4
  151. package/build/core/server/mcpServerLifecycleManager.d.ts.map +1 -1
  152. package/build/core/server/mcpServerLifecycleManager.js +18 -40
  153. package/build/core/server/mcpServerLifecycleManager.js.map +1 -1
  154. package/build/core/server/serverManager.d.ts +1 -0
  155. package/build/core/server/serverManager.d.ts.map +1 -1
  156. package/build/core/server/serverManager.js +32 -0
  157. package/build/core/server/serverManager.js.map +1 -1
  158. package/build/core/server/templateIdentity.d.ts +1 -0
  159. package/build/core/server/templateIdentity.d.ts.map +1 -1
  160. package/build/core/server/templateIdentity.js +11 -1
  161. package/build/core/server/templateIdentity.js.map +1 -1
  162. package/build/core/server/templateServerManager.d.ts +13 -1
  163. package/build/core/server/templateServerManager.d.ts.map +1 -1
  164. package/build/core/server/templateServerManager.js +68 -13
  165. package/build/core/server/templateServerManager.js.map +1 -1
  166. package/build/core/server/toolDescriptionOverrides.d.ts +9 -0
  167. package/build/core/server/toolDescriptionOverrides.d.ts.map +1 -0
  168. package/build/core/server/toolDescriptionOverrides.js +44 -0
  169. package/build/core/server/toolDescriptionOverrides.js.map +1 -0
  170. package/build/core/tools/handlers/serverManagementHandler.d.ts +22 -8
  171. package/build/core/tools/handlers/serverManagementHandler.d.ts.map +1 -1
  172. package/build/core/tools/internal/adapters/helpers/configTransformers.d.ts +3 -1
  173. package/build/core/tools/internal/adapters/helpers/configTransformers.d.ts.map +1 -1
  174. package/build/core/tools/internal/schemas/discovery.d.ts +1 -1
  175. package/build/core/tools/internal/schemas/index.d.ts +3 -3
  176. package/build/core/tools/internal/schemas/management.d.ts +2 -2
  177. package/build/core/types/transport.d.ts +39 -6
  178. package/build/core/types/transport.d.ts.map +1 -1
  179. package/build/core/types/transport.js +61 -2
  180. package/build/core/types/transport.js.map +1 -1
  181. package/build/domains/admin/adminConfiguredServerService.d.ts +65 -4
  182. package/build/domains/admin/adminConfiguredServerService.d.ts.map +1 -1
  183. package/build/domains/admin/adminConfiguredServerService.js +292 -49
  184. package/build/domains/admin/adminConfiguredServerService.js.map +1 -1
  185. package/build/domains/admin/adminDomain.d.ts +19 -0
  186. package/build/domains/admin/adminDomain.d.ts.map +1 -1
  187. package/build/domains/admin/adminDomain.js +17 -0
  188. package/build/domains/admin/adminDomain.js.map +1 -1
  189. package/build/domains/admin/adminInstructionPreviewRuntime.d.ts +7 -0
  190. package/build/domains/admin/adminInstructionPreviewRuntime.d.ts.map +1 -0
  191. package/build/domains/admin/adminInstructionPreviewRuntime.js +154 -0
  192. package/build/domains/admin/adminInstructionPreviewRuntime.js.map +1 -0
  193. package/build/domains/admin/adminInstructionTemplateService.d.ts +169 -0
  194. package/build/domains/admin/adminInstructionTemplateService.d.ts.map +1 -0
  195. package/build/domains/admin/adminInstructionTemplateService.js +181 -0
  196. package/build/domains/admin/adminInstructionTemplateService.js.map +1 -0
  197. package/build/domains/admin/configuredToolInventory.d.ts +64 -0
  198. package/build/domains/admin/configuredToolInventory.d.ts.map +1 -0
  199. package/build/domains/admin/configuredToolInventory.js +182 -0
  200. package/build/domains/admin/configuredToolInventory.js.map +1 -0
  201. package/build/domains/admin/runtimeConfiguredToolInspectionService.d.ts +21 -0
  202. package/build/domains/admin/runtimeConfiguredToolInspectionService.d.ts.map +1 -0
  203. package/build/domains/admin/runtimeConfiguredToolInspectionService.js +255 -0
  204. package/build/domains/admin/runtimeConfiguredToolInspectionService.js.map +1 -0
  205. package/build/domains/config-change/configChange.d.ts +1 -1
  206. package/build/domains/config-change/configChange.d.ts.map +1 -1
  207. package/build/domains/config-change/configChange.js +153 -13
  208. package/build/domains/config-change/configChange.js.map +1 -1
  209. package/build/domains/config-change/types.d.ts +30 -2
  210. package/build/domains/config-change/types.d.ts.map +1 -1
  211. package/build/domains/instruction-template/instructionTemplateManager.d.ts +58 -0
  212. package/build/domains/instruction-template/instructionTemplateManager.d.ts.map +1 -0
  213. package/build/domains/instruction-template/instructionTemplateManager.js +167 -0
  214. package/build/domains/instruction-template/instructionTemplateManager.js.map +1 -0
  215. package/build/domains/runtime-targets/runtimeIdentityVerification.d.ts +1 -0
  216. package/build/domains/runtime-targets/runtimeIdentityVerification.d.ts.map +1 -1
  217. package/build/domains/runtime-targets/runtimeIdentityVerification.js +6 -5
  218. package/build/domains/runtime-targets/runtimeIdentityVerification.js.map +1 -1
  219. package/build/transport/http/routes/adminRoutes.d.ts +2 -0
  220. package/build/transport/http/routes/adminRoutes.d.ts.map +1 -1
  221. package/build/transport/http/routes/adminRoutes.js +345 -9
  222. package/build/transport/http/routes/adminRoutes.js.map +1 -1
  223. package/build/transport/http/routes/apiRoutes.d.ts.map +1 -1
  224. package/build/transport/http/routes/apiRoutes.js +2 -0
  225. package/build/transport/http/routes/apiRoutes.js.map +1 -1
  226. package/build/transport/http/routes/inspectRequestContext.d.ts +2 -0
  227. package/build/transport/http/routes/inspectRequestContext.d.ts.map +1 -1
  228. package/build/transport/http/routes/inspectRequestContext.js +2 -2
  229. package/build/transport/http/routes/inspectRequestContext.js.map +1 -1
  230. package/build/transport/http/routes/inspectRoutes.d.ts +9 -0
  231. package/build/transport/http/routes/inspectRoutes.d.ts.map +1 -1
  232. package/build/transport/http/routes/inspectRoutes.js +15 -10
  233. package/build/transport/http/routes/inspectRoutes.js.map +1 -1
  234. package/build/transport/http/routes/instructionsRoutes.d.ts +4 -0
  235. package/build/transport/http/routes/instructionsRoutes.d.ts.map +1 -0
  236. package/build/transport/http/routes/instructionsRoutes.js +147 -0
  237. package/build/transport/http/routes/instructionsRoutes.js.map +1 -0
  238. package/build/transport/http/routes/toolRoutes.d.ts.map +1 -1
  239. package/build/transport/http/routes/toolRoutes.js +5 -4
  240. package/build/transport/http/routes/toolRoutes.js.map +1 -1
  241. package/build/transport/http/server.d.ts.map +1 -1
  242. package/build/transport/http/server.js +16 -0
  243. package/build/transport/http/server.js.map +1 -1
  244. package/build/transport/transportFactory.d.ts.map +1 -1
  245. package/build/transport/transportFactory.js +34 -12
  246. package/build/transport/transportFactory.js.map +1 -1
  247. package/build/utils/validation/discoveredServer.d.ts +15 -0
  248. package/build/utils/validation/discoveredServer.d.ts.map +1 -0
  249. package/build/utils/validation/discoveredServer.js +2 -0
  250. package/build/utils/validation/discoveredServer.js.map +1 -0
  251. package/build/utils/validation/urlDetection.d.ts +4 -5
  252. package/build/utils/validation/urlDetection.d.ts.map +1 -1
  253. package/build/utils/validation/urlDetection.js +94 -25
  254. package/build/utils/validation/urlDetection.js.map +1 -1
  255. package/package.json +7 -2
  256. package/build/admin/assets/admin-BackendLogsWorkspace-CvJs1npx.js +0 -1
  257. package/build/admin/assets/admin-OAuthServicesWorkspace-BswG57Gm.js +0 -1
  258. package/build/admin/assets/admin-PresetAuthoringWorkspace-BIIRs_EN.js +0 -1
  259. package/build/admin/assets/admin-console-Brz9bnhv.css +0 -1
  260. package/build/admin/assets/admin-console-MT8QZmIC.js +0 -3
  261. package/build/admin/assets/admin-icons-D-JtMXSq.js +0 -1
  262. package/build/admin/assets/admin-mantine-DSFdoMaN.js +0 -53
@@ -0,0 +1,154 @@
1
+ import { randomUUID } from 'node:crypto';
2
+ import { ConfigManager } from '../../config/configManager.js';
3
+ import { FilteringService } from '../../core/filtering/filteringService.js';
4
+ import { createConnectionResolver } from '../../core/server/connectionResolver.js';
5
+ import { prepareRequestContext } from '../../core/server/requestContextPreparation.js';
6
+ import { ClientStatus } from '../../core/types/index.js';
7
+ import { TagQueryParser } from '../../domains/preset/parsers/tagQueryParser.js';
8
+ import { createRequestContextPreparationDependencies } from '../../transport/http/routes/inspectRequestContext.js';
9
+ import { deriveContextSessionId } from '../../transport/http/utils/contextExtractor.js';
10
+ import { normalizeTag } from '../../utils/validation/sanitization.js';
11
+ export function createAdminInstructionPreviewRuntime(serverManager, presetManager, authorizeContext) {
12
+ return async (input) => {
13
+ const aggregator = serverManager.getInstructionAggregator();
14
+ if (!aggregator) {
15
+ return {
16
+ surface: input.surface === 'initialization' ? 'initialize' : 'cli',
17
+ validation: {
18
+ valid: false,
19
+ code: 'runtime_instructions_unavailable',
20
+ message: 'Runtime instructions are unavailable',
21
+ },
22
+ effectiveServers: [],
23
+ unresolvedTemplates: [],
24
+ };
25
+ }
26
+ let preparedSessionId;
27
+ try {
28
+ const filterConfig = toFilterConfig(input, presetManager);
29
+ if (!filterConfig) {
30
+ return invalidPreview(input, 'preset_not_found', 'The selected preset does not exist');
31
+ }
32
+ const declared = ConfigManager.getInstance().loadDeclaredServerConfigs();
33
+ if (input.requestContext) {
34
+ const rawContext = {
35
+ ...input.requestContext,
36
+ sessionId: `admin-preview-${randomUUID()}`,
37
+ };
38
+ const context = authorizeContext?.(rawContext);
39
+ if (!context) {
40
+ return invalidPreview(input, 'request_context_untrusted', 'Request context could not be authorized');
41
+ }
42
+ preparedSessionId = deriveContextSessionId(context);
43
+ await prepareRequestContext({
44
+ deps: createRequestContextPreparationDependencies(serverManager),
45
+ context,
46
+ filterConfig,
47
+ });
48
+ }
49
+ const sessionConnections = createConnectionResolver(serverManager.getClients(), serverManager.getTemplateServerManager()).filterForSession(preparedSessionId);
50
+ const filtered = FilteringService.getFilteredConnections(sessionConnections, filterConfig);
51
+ const representedTemplateNames = new Set(Array.from(filtered.entries())
52
+ .filter(([key, connection]) => key !== connection.name || key.startsWith(`${connection.name}:`))
53
+ .map(([, connection]) => connection.name));
54
+ try {
55
+ const previewConnections = new Map(filtered);
56
+ for (const [name, config] of Object.entries(declared.staticServers)) {
57
+ if (previewConnections.has(name) || !matchesFilter(config.tags, filterConfig))
58
+ continue;
59
+ previewConnections.set(name, asRenderableConnection(name, config.tags));
60
+ }
61
+ return {
62
+ surface: input.surface === 'initialization' ? 'initialize' : 'cli',
63
+ rendered: aggregator.previewInstructions(input.template, filterConfig, previewConnections),
64
+ effectiveServers: Array.from(previewConnections.entries()).map(([key, connection]) => ({
65
+ target: {
66
+ source: key !== connection.name && key.startsWith(`${connection.name}:`) ? 'mcpTemplates' : 'mcpServers',
67
+ name: connection.name,
68
+ },
69
+ hasInstructions: Boolean(aggregator.getEffectiveServerInstructions(key, connection.name)),
70
+ })),
71
+ unresolvedTemplates: Object.entries(declared.templateServers)
72
+ .filter(([name, config]) => !representedTemplateNames.has(name) && matchesFilter(config.tags, filterConfig))
73
+ .map(([name]) => name),
74
+ };
75
+ }
76
+ catch (_error) {
77
+ return {
78
+ surface: input.surface === 'initialization' ? 'initialize' : 'cli',
79
+ validation: {
80
+ valid: false,
81
+ code: 'instruction_template_render_failed',
82
+ message: 'Template rendering failed',
83
+ },
84
+ effectiveServers: [],
85
+ unresolvedTemplates: Object.entries(declared.templateServers)
86
+ .filter(([, config]) => matchesFilter(config.tags, filterConfig))
87
+ .map(([name]) => name),
88
+ };
89
+ }
90
+ }
91
+ catch {
92
+ return invalidPreview(input, 'instruction_preview_failed', 'Instruction preview preparation failed');
93
+ }
94
+ finally {
95
+ if (preparedSessionId) {
96
+ try {
97
+ await serverManager
98
+ .getTemplateServerManager()
99
+ .cleanupTemplateServers(preparedSessionId, serverManager.getClients(), serverManager.getClientTransports());
100
+ }
101
+ catch (_error) {
102
+ // Do not expose runtime paths or configuration details through cleanup failures.
103
+ }
104
+ }
105
+ }
106
+ };
107
+ }
108
+ function asRenderableConnection(name, tags) {
109
+ return {
110
+ name,
111
+ status: ClientStatus.Disconnected,
112
+ transport: { tags: tags ?? [] },
113
+ client: {},
114
+ };
115
+ }
116
+ function matchesFilter(tags, filterConfig) {
117
+ if (!filterConfig.tagFilterMode || filterConfig.tagFilterMode === 'none' || filterConfig.tagFilterMode === 'preset') {
118
+ return true;
119
+ }
120
+ if (filterConfig.tagFilterMode === 'advanced' && filterConfig.tagExpression) {
121
+ return TagQueryParser.evaluate(filterConfig.tagExpression, tags ?? []);
122
+ }
123
+ const requested = (filterConfig.tags ?? []).map(normalizeTag);
124
+ return requested.length === 0 || (tags ?? []).map(normalizeTag).some((tag) => requested.includes(tag));
125
+ }
126
+ function invalidPreview(input, code, message) {
127
+ return {
128
+ surface: input.surface === 'initialization' ? 'initialize' : 'cli',
129
+ validation: { valid: false, code, message },
130
+ effectiveServers: [],
131
+ unresolvedTemplates: [],
132
+ };
133
+ }
134
+ function toFilterConfig(input, presetManager) {
135
+ switch (input.selection.mode) {
136
+ case 'tags':
137
+ return { tagFilterMode: 'simple-or', tags: input.selection.tags };
138
+ case 'tag-filter':
139
+ return { tagFilterMode: 'advanced', tagExpression: TagQueryParser.parseAdvanced(input.selection.expression) };
140
+ case 'preset': {
141
+ const expression = presetManager?.resolvePresetToExpression(input.selection.preset);
142
+ return expression
143
+ ? {
144
+ tagFilterMode: 'advanced',
145
+ tagExpression: TagQueryParser.parseAdvanced(expression),
146
+ presetName: input.selection.preset,
147
+ }
148
+ : undefined;
149
+ }
150
+ default:
151
+ return { tagFilterMode: 'none' };
152
+ }
153
+ }
154
+ //# sourceMappingURL=adminInstructionPreviewRuntime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adminInstructionPreviewRuntime.js","sourceRoot":"","sources":["../../../src/domains/admin/adminInstructionPreviewRuntime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAE7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,yCAA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AAI,EAAE,CAAC;QAC7B,KAAK,MAAM;YACT,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,IAAI,EAAE,KAAK,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC;QACpE,KAAK,YAAY;YACf,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,aAAa,EAAE,cAAc,CAAC,aAAa,CAAC,KAAK,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE,CAAC;QAChH,KAAK,QAAQ,CAAC,CAAC,CAAC;YACd,MAAM,UAAU,GAAG,aAAa,EAAE,yBAAyB,CAAC,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;YACpF,OAAO,UAAU;gBACf,CAAC,CAAC;oBACE,aAAa,EAAE,UAAU;oBACzB,aAAa,EAAE,cAAc,CAAC,aAAa,CAAC,UAAU,CAAC;oBACvD,UAAU,EAAE,KAAK,CAAC,SAAS,CAAC,MAAM;iBACnC;gBACH,CAAC,CAAC,SAAS,CAAC;QAChB,CAAC;QACD;YACE,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,CAAC;IACrC,CAAC;AACH,CAAC"}
@@ -0,0 +1,169 @@
1
+ import type { InstructionSurface } from '../../core/instructions/instructionAggregator.js';
2
+ import type { InstructionTemplateConfig } from '../../core/types/transport.js';
3
+ import type { ConfiguredServerTargetSource } from '../../domains/config-change/configChange.js';
4
+ import type { InstructionTemplateCollectionReadModel, InstructionTemplateManager, InstructionTemplateMutationResult, InstructionTemplateReadModel, InstructionTemplateValidation } from '../../domains/instruction-template/instructionTemplateManager.js';
5
+ import type { ContextData } from '../../types/context.js';
6
+ import type { AdminOperationContext, AdminOperationResult, AdminOperationService } from './adminOperationService.js';
7
+ export type InstructionPreviewSelection = {
8
+ mode: 'all';
9
+ } | {
10
+ mode: 'preset';
11
+ preset: string;
12
+ } | {
13
+ mode: 'tags';
14
+ tags: string[];
15
+ } | {
16
+ mode: 'tag-filter';
17
+ expression: string;
18
+ };
19
+ export type InstructionPreviewSurface = 'initialize' | 'cli';
20
+ export interface AdminInstructionPreviewInput {
21
+ identity: string;
22
+ surface: InstructionSurface;
23
+ template: string;
24
+ selection: InstructionPreviewSelection;
25
+ requestContext?: ContextData;
26
+ }
27
+ export interface AdminInstructionPreviewServerFact {
28
+ target: {
29
+ source: ConfiguredServerTargetSource;
30
+ name: string;
31
+ };
32
+ hasInstructions: boolean;
33
+ }
34
+ export interface AdminInstructionPreviewResult {
35
+ surface: InstructionPreviewSurface;
36
+ rendered?: string;
37
+ validation?: {
38
+ valid: false;
39
+ code: string;
40
+ message: string;
41
+ };
42
+ effectiveServers: AdminInstructionPreviewServerFact[];
43
+ unresolvedTemplates: string[];
44
+ }
45
+ export interface SanitizedInstructionRenderFailure {
46
+ code: 'managed_template_render_failed';
47
+ surface: InstructionPreviewSurface;
48
+ templateIdentity: string;
49
+ occurredAt: string;
50
+ }
51
+ export interface RuntimeInstructionRenderFailure {
52
+ surface: InstructionSurface;
53
+ templateIdentity: string;
54
+ error: string;
55
+ occurredAt: Date;
56
+ }
57
+ export interface AdminInstructionTemplateOperations {
58
+ listTemplates(input: {
59
+ context: AdminOperationContext;
60
+ }): Promise<AdminOperationResult<InstructionTemplateAdminState>>;
61
+ getTemplate(input: {
62
+ context: AdminOperationContext;
63
+ identity: string;
64
+ }): Promise<AdminOperationResult<InstructionTemplateDetail>>;
65
+ createTemplate(input: TemplateSaveOperationInput): Promise<AdminOperationResult<InstructionTemplateMutationResult>>;
66
+ updateTemplate(input: TemplateSaveOperationInput): Promise<AdminOperationResult<InstructionTemplateMutationResult>>;
67
+ cloneTemplate(input: TemplateCloneOperationInput): Promise<AdminOperationResult<InstructionTemplateMutationResult>>;
68
+ validateTemplate(input: TemplateIdentityOperationInput): Promise<AdminOperationResult<TemplateValidationPreview>>;
69
+ previewTemplate(input: TemplatePreviewOperationInput): Promise<AdminOperationResult<AdminInstructionPreviewResult>>;
70
+ activateTemplate(input: TemplateIdentityOperationInput): Promise<AdminOperationResult<InstructionTemplateMutationResult>>;
71
+ importLegacyTemplate(input: TemplateIdentityOperationInput): Promise<AdminOperationResult<InstructionTemplateMutationResult | {
72
+ status: 'legacy_unavailable';
73
+ }>>;
74
+ previewDeleteTemplate(input: TemplateIdentityOperationInput): Promise<AdminOperationResult<TemplateDeletePreview>>;
75
+ deleteTemplate(input: TemplateIdentityOperationInput): Promise<AdminOperationResult<InstructionTemplateMutationResult>>;
76
+ }
77
+ export interface InstructionTemplateAdminState extends InstructionTemplateCollectionReadModel {
78
+ renderFailures: Partial<Record<InstructionPreviewSurface, SanitizedInstructionRenderFailure>>;
79
+ legacyImportAvailable: boolean;
80
+ }
81
+ export interface InstructionTemplateDetail {
82
+ template: InstructionTemplateReadModel;
83
+ configFingerprint: string;
84
+ renderFailures: Partial<Record<InstructionPreviewSurface, SanitizedInstructionRenderFailure>>;
85
+ }
86
+ export interface TemplateDeletePreview {
87
+ identity: string;
88
+ allowed: boolean;
89
+ reason?: 'protected' | 'active_conflict' | 'not_found';
90
+ expectedConfigFingerprint: string;
91
+ previewFingerprint: string;
92
+ }
93
+ export interface TemplateValidationPreview {
94
+ identity: string;
95
+ validation?: InstructionTemplateValidation;
96
+ expectedConfigFingerprint: string;
97
+ previewFingerprint: string;
98
+ }
99
+ interface TemplateIdentityOperationInput {
100
+ context: AdminOperationContext;
101
+ identity: string;
102
+ expectedConfigFingerprint: string;
103
+ previewFingerprint?: string;
104
+ }
105
+ interface TemplateSaveOperationInput extends TemplateIdentityOperationInput {
106
+ variants: InstructionTemplateConfig;
107
+ }
108
+ interface TemplateCloneOperationInput extends TemplateIdentityOperationInput {
109
+ sourceIdentity: string;
110
+ }
111
+ interface TemplatePreviewOperationInput {
112
+ context: AdminOperationContext;
113
+ identity: string;
114
+ surface: InstructionPreviewSurface;
115
+ selection: InstructionPreviewSelection;
116
+ requestContext?: ContextData;
117
+ }
118
+ interface AdminInstructionTemplateServiceOptions {
119
+ operationService: AdminOperationService;
120
+ manager: InstructionTemplateManager;
121
+ preview: (input: AdminInstructionPreviewInput) => Promise<AdminInstructionPreviewResult>;
122
+ getLegacyInitialization: () => string | undefined;
123
+ getRenderFailures: () => Partial<Record<InstructionSurface, RuntimeInstructionRenderFailure>>;
124
+ }
125
+ export declare class AdminInstructionTemplateNotFoundError extends Error {
126
+ readonly identity: string;
127
+ readonly code = "instruction_template_not_found";
128
+ constructor(identity: string);
129
+ }
130
+ export declare class AdminInstructionTemplateService implements AdminInstructionTemplateOperations {
131
+ private readonly options;
132
+ constructor(options: AdminInstructionTemplateServiceOptions);
133
+ listTemplates(input: {
134
+ context: AdminOperationContext;
135
+ }): Promise<AdminOperationResult<InstructionTemplateAdminState>>;
136
+ getTemplate(input: {
137
+ context: AdminOperationContext;
138
+ identity: string;
139
+ }): Promise<AdminOperationResult<{
140
+ template: InstructionTemplateReadModel;
141
+ configFingerprint: string;
142
+ renderFailures: Partial<Record<InstructionPreviewSurface, SanitizedInstructionRenderFailure>>;
143
+ }>>;
144
+ createTemplate(input: TemplateSaveOperationInput): Promise<AdminOperationResult<InstructionTemplateMutationResult>>;
145
+ updateTemplate(input: TemplateSaveOperationInput): Promise<AdminOperationResult<InstructionTemplateMutationResult>>;
146
+ cloneTemplate(input: TemplateCloneOperationInput): Promise<AdminOperationResult<InstructionTemplateMutationResult>>;
147
+ validateTemplate(input: TemplateIdentityOperationInput): Promise<AdminOperationResult<{
148
+ identity: string;
149
+ validation: InstructionTemplateValidation | undefined;
150
+ expectedConfigFingerprint: string;
151
+ previewFingerprint: string;
152
+ }>>;
153
+ previewTemplate(input: TemplatePreviewOperationInput): Promise<AdminOperationResult<AdminInstructionPreviewResult>>;
154
+ activateTemplate(input: TemplateIdentityOperationInput): Promise<AdminOperationResult<InstructionTemplateMutationResult>>;
155
+ importLegacyTemplate(input: TemplateIdentityOperationInput): Promise<AdminOperationResult<import("../../domains/config-change/configChange.js").ConfigChangeResult | {
156
+ status: "protected" | "active_conflict" | "identity_conflict" | "not_found" | "conflict";
157
+ } | {
158
+ status: "invalid";
159
+ validation: InstructionTemplateValidation;
160
+ } | {
161
+ status: "legacy_unavailable";
162
+ }>>;
163
+ previewDeleteTemplate(input: TemplateIdentityOperationInput): Promise<AdminOperationResult<TemplateDeletePreview>>;
164
+ deleteTemplate(input: TemplateIdentityOperationInput): Promise<AdminOperationResult<InstructionTemplateMutationResult>>;
165
+ private mutate;
166
+ private readAdminState;
167
+ }
168
+ export {};
169
+ //# sourceMappingURL=adminInstructionTemplateService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adminInstructionTemplateService.d.ts","sourceRoot":"","sources":["../../../src/domains/admin/adminInstructionTemplateService.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iDAAiD,CAAC;AAC1F,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,8BAA8B,CAAC;AAC9E,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,4CAA4C,CAAC;AAC/F,OAAO,KAAK,EACV,sCAAsC,EACtC,0BAA0B,EAC1B,iCAAiC,EACjC,4BAA4B,EAC5B,6BAA6B,EAC9B,MAAM,iEAAiE,CAAC;AACzE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEzD,OAAO,KAAK,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAErH,MAAM,MAAM,2BAA2B,GACnC;IAAE,IAAI,EAAE,KAAK,CAAA;CAAE,GACf;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAClC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,EAAE,CAAA;CAAE,GAChC;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAAC;AAC/C,MAAM,MAAM,yBAAyB,GAAG,YAAY,GAAG,KAAK,CAAC;AAE7D,MAAM,WAAW,4BAA4B;IAC3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AAC,MAAM,CAAC,kBAAkB,EAAE,+BAA+B,CAAC,CAAC,CAAC;CAC/F;AAED,qBAAa,qCAAsC,SAAQ,KAAK;IAGlD,QAAQ,CAAC,QAAQ,EAAE,MAAM;IAFrC,QAAQ,CAAC,IAAI,oCAAoC;gBAE5B,QAAQ,EAAE,MAAM;CAItC;AAED,qBAAa,+BAAgC,YAAW,kCAAkC;IAC5E,OAAO,CAAC,QAAQ,CAAC,OAAO;gBAAP,OAAO,EAAE,sCAAsC;IAE5E,aAAa,CAAC,KAAK,EAAE;QAAE,OAAO,EAAE,qBAAqB,CAAA;KAAE;IAQvD,WAAW,CAAC,KAAK,EAAE;QAAE,OAAO,EAAE,qBAAqB,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE;;;;;IAavE,cAAc,CAAC,KAAK,EAAE,0BAA0B;IAUhD,cAAc,CAAC,KAAK,EAAE,0BAA0B;IAUhD,aAAa,CAAC,KAAK,EAAE,2BAA2B;IAUhD,gBAAgB,CAAC,KAAK,EAAE,8BAA8B;;;;;;IAgBtD,eAAe,CAAC,KAAK,EAAE,6BAA6B;IAmBpD,gBAAgB,CAAC,KAAK,EAAE,8BAA8B;IAWtD,oBAAoB,CAAC,KAAK,EAAE,8BAA8B;;;;;;;;IAa1D,qBAAqB,CAAC,KAAK,EAAE,8BAA8B;IAwB3D,cAAc,CAAC,KAAK,EAAE,8BAA8B;IAWpD,OAAO,CAAC,MAAM;YAQA,cAAc;CAQ7B"}
@@ -0,0 +1,181 @@
1
+ import { createHash } from 'node:crypto';
2
+ export class AdminInstructionTemplateNotFoundError extends Error {
3
+ identity;
4
+ code = 'instruction_template_not_found';
5
+ constructor(identity) {
6
+ super(`Instruction template '${identity}' was not found`);
7
+ this.identity = identity;
8
+ this.name = 'AdminInstructionTemplateNotFoundError';
9
+ }
10
+ }
11
+ export class AdminInstructionTemplateService {
12
+ options;
13
+ constructor(options) {
14
+ this.options = options;
15
+ }
16
+ listTemplates(input) {
17
+ return this.options.operationService.executeReadOnly({
18
+ context: input.context,
19
+ operationName: 'listInstructionTemplates',
20
+ run: async () => this.readAdminState(),
21
+ });
22
+ }
23
+ getTemplate(input) {
24
+ return this.options.operationService.executeReadOnly({
25
+ context: withTemplateTarget(input.context, input.identity),
26
+ operationName: 'getInstructionTemplate',
27
+ run: async () => {
28
+ const state = await this.readAdminState();
29
+ const template = state.templates.find((candidate) => candidate.identity === input.identity);
30
+ if (!template)
31
+ throw new AdminInstructionTemplateNotFoundError(input.identity);
32
+ return { template, configFingerprint: state.configFingerprint, renderFailures: state.renderFailures };
33
+ },
34
+ });
35
+ }
36
+ createTemplate(input) {
37
+ return this.mutate('createInstructionTemplate', input, () => this.options.manager.create({
38
+ identity: input.identity,
39
+ template: input.variants,
40
+ expectedConfigFingerprint: input.expectedConfigFingerprint,
41
+ }));
42
+ }
43
+ updateTemplate(input) {
44
+ return this.mutate('updateInstructionTemplate', input, () => this.options.manager.update({
45
+ identity: input.identity,
46
+ template: input.variants,
47
+ expectedConfigFingerprint: input.expectedConfigFingerprint,
48
+ }));
49
+ }
50
+ cloneTemplate(input) {
51
+ return this.mutate('cloneInstructionTemplate', input, () => this.options.manager.clone({
52
+ sourceIdentity: input.sourceIdentity,
53
+ identity: input.identity,
54
+ expectedConfigFingerprint: input.expectedConfigFingerprint,
55
+ }));
56
+ }
57
+ validateTemplate(input) {
58
+ return this.options.operationService.executeReadOnly({
59
+ context: withTemplateTarget(input.context, input.identity),
60
+ operationName: 'validateInstructionTemplate',
61
+ run: async () => {
62
+ const state = await this.options.manager.list();
63
+ return {
64
+ identity: input.identity,
65
+ validation: await this.options.manager.validate(input.identity),
66
+ expectedConfigFingerprint: state.configFingerprint,
67
+ previewFingerprint: previewFingerprint('activate', input.identity, state.configFingerprint),
68
+ };
69
+ },
70
+ });
71
+ }
72
+ previewTemplate(input) {
73
+ return this.options.operationService.executeDryRun({
74
+ context: withTemplateTarget(input.context, input.identity),
75
+ operationName: 'previewInstructionTemplate',
76
+ run: async () => {
77
+ const state = await this.options.manager.list();
78
+ const template = state.templates.find((candidate) => candidate.identity === input.identity);
79
+ if (!template)
80
+ throw new AdminInstructionTemplateNotFoundError(input.identity);
81
+ return this.options.preview({
82
+ identity: input.identity,
83
+ surface: input.surface === 'initialize' ? 'initialization' : 'cli',
84
+ template: template.variants[input.surface === 'initialize' ? 'initialization' : 'cli'],
85
+ selection: input.selection,
86
+ requestContext: input.requestContext,
87
+ });
88
+ },
89
+ });
90
+ }
91
+ activateTemplate(input) {
92
+ return this.mutate('activateInstructionTemplate', input, () => input.previewFingerprint !== previewFingerprint('activate', input.identity, input.expectedConfigFingerprint)
93
+ ? Promise.resolve({ status: 'conflict' })
94
+ : this.options.manager.activate({
95
+ identity: input.identity,
96
+ expectedConfigFingerprint: input.expectedConfigFingerprint,
97
+ }));
98
+ }
99
+ importLegacyTemplate(input) {
100
+ return this.mutate('importLegacyInstructionTemplate', input, async () => {
101
+ const initialization = this.options.getLegacyInitialization();
102
+ return initialization === undefined
103
+ ? { status: 'legacy_unavailable' }
104
+ : this.options.manager.importLegacy({
105
+ identity: input.identity,
106
+ initialization,
107
+ expectedConfigFingerprint: input.expectedConfigFingerprint,
108
+ });
109
+ });
110
+ }
111
+ previewDeleteTemplate(input) {
112
+ return this.options.operationService.executeDryRun({
113
+ context: withTemplateTarget(input.context, input.identity),
114
+ operationName: 'previewDeleteInstructionTemplate',
115
+ run: async () => {
116
+ const state = await this.options.manager.list();
117
+ const template = state.templates.find((candidate) => candidate.identity === input.identity);
118
+ return {
119
+ identity: input.identity,
120
+ allowed: Boolean(template && !template.protected && !template.active),
121
+ reason: !template
122
+ ? 'not_found'
123
+ : template.protected
124
+ ? 'protected'
125
+ : template.active
126
+ ? 'active_conflict'
127
+ : undefined,
128
+ expectedConfigFingerprint: state.configFingerprint,
129
+ previewFingerprint: previewFingerprint('delete', input.identity, state.configFingerprint),
130
+ };
131
+ },
132
+ });
133
+ }
134
+ deleteTemplate(input) {
135
+ return this.mutate('deleteInstructionTemplate', input, () => input.previewFingerprint !== previewFingerprint('delete', input.identity, input.expectedConfigFingerprint)
136
+ ? Promise.resolve({ status: 'conflict' })
137
+ : this.options.manager.delete({
138
+ identity: input.identity,
139
+ expectedConfigFingerprint: input.expectedConfigFingerprint,
140
+ }));
141
+ }
142
+ mutate(operationName, input, run) {
143
+ return this.options.operationService.executeMutation({
144
+ context: withTemplateTarget(input.context, input.identity),
145
+ operationName,
146
+ run,
147
+ });
148
+ }
149
+ async readAdminState() {
150
+ const state = await this.options.manager.list();
151
+ return {
152
+ ...state,
153
+ legacyImportAvailable: this.options.getLegacyInitialization() !== undefined,
154
+ renderFailures: sanitizeRenderFailures(this.options.getRenderFailures()),
155
+ };
156
+ }
157
+ }
158
+ function previewFingerprint(action, identity, configFingerprint) {
159
+ return `instruction_template_preview_${createHash('sha256')
160
+ .update(action)
161
+ .update('\0')
162
+ .update(identity)
163
+ .update('\0')
164
+ .update(configFingerprint)
165
+ .digest('hex')}`;
166
+ }
167
+ function withTemplateTarget(context, identity) {
168
+ return { ...context, target: { type: 'instruction_template', id: identity } };
169
+ }
170
+ function sanitizeRenderFailures(failures) {
171
+ return Object.fromEntries(Object.entries(failures).map(([surface, failure]) => [
172
+ surface === 'initialization' ? 'initialize' : 'cli',
173
+ {
174
+ code: 'managed_template_render_failed',
175
+ surface: failure.surface === 'initialization' ? 'initialize' : 'cli',
176
+ templateIdentity: failure.templateIdentity,
177
+ occurredAt: failure.occurredAt.toISOString(),
178
+ },
179
+ ]));
180
+ }
181
+ //# sourceMappingURL=adminInstructionTemplateService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adminInstructionTemplateService.js","sourceRoot":"","sources":["../../../src/domains/admin/adminInstructionTemplateService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AA4IzC,MAAM,OAAO,qCAAsC,SAAQ,KAAK;IAGzC;IAFZ,IAAI,GAAG,gCAAgC,CAAC;IAEjD,YAAqB,QA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ACvB,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,EAAE,CAAC;QACnD,OAAO,KAAK,gBAAgB,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,KAAK;QACnD;YACE,IAAI,EAAE,gCAAgC;YACtC,OAAO,EAAE,OAAO,CAAC,OAAO,KAAK,gBAAgB,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,KAAK;YACpE,gBAAgB,EAAE,OAAO,CAAC,gBAAgB;YAC1C,UAAU,EAAE,OAAO,CAAC,UAAU,CAAC,WAAW,EAAE;SAC7C;KACF,CAAC,CACH,CAAC;AACJ,CAAC"}
@@ -0,0 +1,64 @@
1
+ import { type MCPServerParams, type OutboundConnection, type OutboundConnections } from '../../core/types/index.js';
2
+ export type ConfiguredToolTargetSource = 'mcpServers' | 'mcpTemplates';
3
+ export type ConfiguredToolInspectionStatus = 'unavailable' | 'in_progress' | 'failed' | 'complete';
4
+ export interface ConfiguredToolInspectionFact {
5
+ instanceId: string;
6
+ status: 'unavailable' | 'failed' | 'complete';
7
+ error?: string;
8
+ }
9
+ export interface ConfiguredToolInspectionOutcome {
10
+ status: ConfiguredToolInspectionStatus;
11
+ reason?: string;
12
+ retryable: boolean;
13
+ instances: ConfiguredToolInspectionFact[];
14
+ }
15
+ export interface ConfiguredToolInventoryRow {
16
+ name: string;
17
+ upstreamDescription?: string;
18
+ effectiveDescription?: string;
19
+ descriptionOverride?: string;
20
+ descriptionOverridden: boolean;
21
+ enabled: boolean;
22
+ observed: boolean;
23
+ stale?: boolean;
24
+ unresolved: boolean;
25
+ observedInstanceCount: number;
26
+ activeInstanceCount: number;
27
+ observedInSomeInstances: boolean;
28
+ approximateTokens: number;
29
+ }
30
+ export interface ConfiguredToolInventory {
31
+ targetName: string;
32
+ source: ConfiguredToolTargetSource;
33
+ targetEnabled: boolean;
34
+ freshness: 'live' | 'unavailable';
35
+ model: string;
36
+ generation: string;
37
+ activeInstanceCount: number;
38
+ inspection?: ConfiguredToolInspectionOutcome;
39
+ rows: ConfiguredToolInventoryRow[];
40
+ counts: {
41
+ observed: number;
42
+ enabled: number;
43
+ disabled: number;
44
+ unresolved: number;
45
+ };
46
+ approximateTokens: {
47
+ enabled: number;
48
+ allObserved: number;
49
+ savings: number;
50
+ };
51
+ }
52
+ export declare function createConfiguredToolInventory(input: {
53
+ targetName: string;
54
+ source: ConfiguredToolTargetSource;
55
+ config: MCPServerParams;
56
+ connections: OutboundConnections;
57
+ model?: string;
58
+ instances?: Array<{
59
+ instanceId: string;
60
+ connection: OutboundConnection;
61
+ }>;
62
+ inspection?: ConfiguredToolInspectionOutcome;
63
+ }): Promise<ConfiguredToolInventory>;
64
+ //# sourceMappingURL=configuredToolInventory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"configuredToolInventory.d.ts","sourceRoot":"","sources":["../../../src/domains/admin/configuredToolInventory.ts"],"names":[],"mappings":"AAeA,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,EACzB,MAAM,0BAA0B,CAAC;AAGlC,MAAM,MAAM,0BAA0B,GAAG,YAAY,GAAG,cAAc,CAAC;AAEvE,MAAM,MAAM,8BAA8B,GAAG,aAAa,GAAG,aAAa,GAAG,QAAQ,GAAG,UAAU,CAAC;AAEnG,MAAM,WAAW,4BAA4B;IAC3C,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,aAAa,GAAG,QAAQ,GAAG,UAAU,CAAC;IAC9C,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,+BAA+B;IAC9C,MAAM,EAAE,8BAA8B,CAAC;IACvC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,OAAO,CAAC;IACnB,SAAS,EAAE,4BAA4B,EAAE,CAAC;CAC3C;AAED,MAAM,WAAW,0BAA0B;IACzC,IAAI,EAA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