@evalops/maestro 0.10.23 → 0.10.24

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 (376) hide show
  1. package/README.md +4 -4
  2. package/dist/agent/agent.d.ts +2 -2
  3. package/dist/agent/agent.d.ts.map +1 -1
  4. package/dist/agent/agent.js +1 -1
  5. package/dist/agent/agent.js.map +1 -1
  6. package/dist/agent/keys.d.ts +2 -5
  7. package/dist/agent/keys.d.ts.map +1 -1
  8. package/dist/agent/keys.js +4 -5
  9. package/dist/agent/keys.js.map +1 -1
  10. package/dist/agent/modes.d.ts +2 -2
  11. package/dist/agent/modes.d.ts.map +1 -1
  12. package/dist/agent/modes.js +6 -7
  13. package/dist/agent/modes.js.map +1 -1
  14. package/dist/agent/providers/anthropic.d.ts.map +1 -1
  15. package/dist/agent/providers/anthropic.js +4 -4
  16. package/dist/agent/providers/anthropic.js.map +1 -1
  17. package/dist/agent/providers/google.js +1 -1
  18. package/dist/agent/swarm/executor.d.ts +2 -0
  19. package/dist/agent/swarm/executor.d.ts.map +1 -1
  20. package/dist/agent/swarm/executor.js +208 -35
  21. package/dist/agent/swarm/executor.js.map +1 -1
  22. package/dist/agent/swarm/types.d.ts +2 -0
  23. package/dist/agent/swarm/types.d.ts.map +1 -1
  24. package/dist/agent/swarm/types.js.map +1 -1
  25. package/dist/agent/tool-capability-types.d.ts +36 -0
  26. package/dist/agent/tool-capability-types.d.ts.map +1 -0
  27. package/dist/agent/tool-capability-types.js +2 -0
  28. package/dist/agent/tool-capability-types.js.map +1 -0
  29. package/dist/agent/transport/tool-execution-bridge.d.ts +13 -0
  30. package/dist/agent/transport/tool-execution-bridge.d.ts.map +1 -1
  31. package/dist/agent/transport/tool-execution-bridge.js +28 -15
  32. package/dist/agent/transport/tool-execution-bridge.js.map +1 -1
  33. package/dist/agent/transport/transport-utils.d.ts.map +1 -1
  34. package/dist/agent/transport/transport-utils.js +2 -3
  35. package/dist/agent/transport/transport-utils.js.map +1 -1
  36. package/dist/agent/transport.js +1 -1
  37. package/dist/agent/transport.js.map +1 -1
  38. package/dist/agent/type-guards.d.ts +1 -1
  39. package/dist/agent/type-guards.js +1 -1
  40. package/dist/agent/type-guards.js.map +1 -1
  41. package/dist/agent/types.d.ts +5 -3
  42. package/dist/agent/types.d.ts.map +1 -1
  43. package/dist/agent/types.js +2 -2
  44. package/dist/agent/types.js.map +1 -1
  45. package/dist/app-server/daemon-lifecycle-api.d.ts +31 -0
  46. package/dist/app-server/daemon-lifecycle-api.d.ts.map +1 -0
  47. package/dist/app-server/daemon-lifecycle-api.js +259 -0
  48. package/dist/app-server/daemon-lifecycle-api.js.map +1 -0
  49. package/dist/app-server/external-agent-import-api.d.ts +30 -0
  50. package/dist/app-server/external-agent-import-api.d.ts.map +1 -0
  51. package/dist/app-server/external-agent-import-api.js +553 -0
  52. package/dist/app-server/external-agent-import-api.js.map +1 -0
  53. package/dist/app-server/host-control-api.d.ts +30 -0
  54. package/dist/app-server/host-control-api.d.ts.map +1 -0
  55. package/dist/app-server/host-control-api.js +343 -0
  56. package/dist/app-server/host-control-api.js.map +1 -0
  57. package/dist/app-server/in-process-client.d.ts +2 -2
  58. package/dist/app-server/in-process-client.d.ts.map +1 -1
  59. package/dist/app-server/in-process-client.js.map +1 -1
  60. package/dist/app-server/network-governance-api.d.ts +26 -0
  61. package/dist/app-server/network-governance-api.d.ts.map +1 -0
  62. package/dist/app-server/network-governance-api.js +476 -0
  63. package/dist/app-server/network-governance-api.js.map +1 -0
  64. package/dist/app-server/plugin-bundle-api.d.ts +17 -0
  65. package/dist/app-server/plugin-bundle-api.d.ts.map +1 -0
  66. package/dist/app-server/plugin-bundle-api.js +219 -0
  67. package/dist/app-server/plugin-bundle-api.js.map +1 -0
  68. package/dist/app-server/policy-control-api.d.ts +14 -0
  69. package/dist/app-server/policy-control-api.d.ts.map +1 -0
  70. package/dist/app-server/policy-control-api.js +200 -0
  71. package/dist/app-server/policy-control-api.js.map +1 -0
  72. package/dist/app-server/protocol-modes-api.d.ts +22 -0
  73. package/dist/app-server/protocol-modes-api.d.ts.map +1 -0
  74. package/dist/app-server/protocol-modes-api.js +124 -0
  75. package/dist/app-server/protocol-modes-api.js.map +1 -0
  76. package/dist/app-server/sandbox-proof-api.d.ts +21 -0
  77. package/dist/app-server/sandbox-proof-api.d.ts.map +1 -0
  78. package/dist/app-server/sandbox-proof-api.js +127 -0
  79. package/dist/app-server/sandbox-proof-api.js.map +1 -0
  80. package/dist/app-server/session-api.d.ts +93 -3
  81. package/dist/app-server/session-api.d.ts.map +1 -1
  82. package/dist/app-server/session-api.js +706 -18
  83. package/dist/app-server/session-api.js.map +1 -1
  84. package/dist/audit/logger.d.ts +1 -1
  85. package/dist/bootstrap/auth-setup.d.ts.map +1 -1
  86. package/dist/bootstrap/auth-setup.js +17 -2
  87. package/dist/bootstrap/auth-setup.js.map +1 -1
  88. package/dist/bootstrap/model-resolution-setup.d.ts.map +1 -1
  89. package/dist/bootstrap/model-resolution-setup.js +19 -4
  90. package/dist/bootstrap/model-resolution-setup.js.map +1 -1
  91. package/dist/cli/args.d.ts +2 -2
  92. package/dist/cli/args.d.ts.map +1 -1
  93. package/dist/cli/args.js +2 -2
  94. package/dist/cli/args.js.map +1 -1
  95. package/dist/cli/commands/a2a.d.ts.map +1 -1
  96. package/dist/cli/commands/a2a.js +226 -14
  97. package/dist/cli/commands/a2a.js.map +1 -1
  98. package/dist/cli/commands/anthropic.d.ts +1 -1
  99. package/dist/cli/commands/anthropic.d.ts.map +1 -1
  100. package/dist/cli/commands/anthropic.js +3 -68
  101. package/dist/cli/commands/anthropic.js.map +1 -1
  102. package/dist/cli/commands/modes.js +1 -1
  103. package/dist/cli/commands/modes.js.map +1 -1
  104. package/dist/cli/help.d.ts.map +1 -1
  105. package/dist/cli/help.js +5 -7
  106. package/dist/cli/help.js.map +1 -1
  107. package/dist/cli/rpc-mode.d.ts +1 -1
  108. package/dist/cli/rpc-mode.js +1 -1
  109. package/dist/cli/rpc-mode.js.map +1 -1
  110. package/dist/cli/session.js +1 -1
  111. package/dist/cli/session.js.map +1 -1
  112. package/dist/cli-tui/commands/command-catalog.d.ts.map +1 -1
  113. package/dist/cli-tui/commands/command-catalog.js +7 -12
  114. package/dist/cli-tui/commands/command-catalog.js.map +1 -1
  115. package/dist/cli-tui/commands/subcommands/auth-commands.d.ts +1 -1
  116. package/dist/cli-tui/commands/subcommands/auth-commands.d.ts.map +1 -1
  117. package/dist/cli-tui/commands/subcommands/auth-commands.js +4 -12
  118. package/dist/cli-tui/commands/subcommands/auth-commands.js.map +1 -1
  119. package/dist/cli-tui/custom-editor.d.ts +1 -1
  120. package/dist/cli-tui/custom-editor.js +2 -2
  121. package/dist/cli-tui/custom-editor.js.map +1 -1
  122. package/dist/cli-tui/oauth/oauth-flow-controller.d.ts.map +1 -1
  123. package/dist/cli-tui/oauth/oauth-flow-controller.js +19 -23
  124. package/dist/cli-tui/oauth/oauth-flow-controller.js.map +1 -1
  125. package/dist/cli-tui/selectors/model-selector.d.ts.map +1 -1
  126. package/dist/cli-tui/selectors/model-selector.js +0 -1
  127. package/dist/cli-tui/selectors/model-selector.js.map +1 -1
  128. package/dist/cli-tui/selectors/oauth-selector-view.d.ts +2 -2
  129. package/dist/cli-tui/selectors/oauth-selector-view.d.ts.map +1 -1
  130. package/dist/cli-tui/selectors/oauth-selector-view.js.map +1 -1
  131. package/dist/cli-tui/selectors/oauth-selector.d.ts +2 -2
  132. package/dist/cli-tui/selectors/oauth-selector.d.ts.map +1 -1
  133. package/dist/cli-tui/selectors/oauth-selector.js +3 -4
  134. package/dist/cli-tui/selectors/oauth-selector.js.map +1 -1
  135. package/dist/cli-tui/tui-renderer/mcp-events-setup.js +1 -1
  136. package/dist/cli-tui/tui-renderer/mcp-events-setup.js.map +1 -1
  137. package/dist/cli-tui/tui-renderer.js +2 -2
  138. package/dist/cli-tui/tui-renderer.js.map +1 -1
  139. package/dist/cli-tui/utils/footer-utils.d.ts +1 -1
  140. package/dist/cli-tui/utils/footer-utils.js +1 -1
  141. package/dist/cli-tui/utils/footer-utils.js.map +1 -1
  142. package/dist/cli.js +15156 -14232
  143. package/dist/commands/prompts.d.ts +1 -1
  144. package/dist/commands/prompts.js +1 -1
  145. package/dist/commands/prompts.js.map +1 -1
  146. package/dist/config/constants.d.ts +2 -2
  147. package/dist/config/constants.d.ts.map +1 -1
  148. package/dist/config/constants.js +2 -2
  149. package/dist/config/constants.js.map +1 -1
  150. package/dist/config/index.d.ts +1 -1
  151. package/dist/config/index.js +1 -1
  152. package/dist/config/index.js.map +1 -1
  153. package/dist/config/toml-config.js +3 -3
  154. package/dist/config/toml-config.js.map +1 -1
  155. package/dist/db/client.d.ts +2 -2
  156. package/dist/db/client.js +2 -2
  157. package/dist/db/client.js.map +1 -1
  158. package/dist/db/migrate.d.ts +1 -1
  159. package/dist/db/migrate.js +1 -1
  160. package/dist/db/migrate.js.map +1 -1
  161. package/dist/db/schema.d.ts +2 -2
  162. package/dist/db/schema.js +1 -1
  163. package/dist/db/schema.js.map +1 -1
  164. package/dist/errors/index.d.ts +2 -2
  165. package/dist/errors/index.js +2 -2
  166. package/dist/errors/index.js.map +1 -1
  167. package/dist/main.d.ts +4 -5
  168. package/dist/main.d.ts.map +1 -1
  169. package/dist/main.js +17 -14
  170. package/dist/main.js.map +1 -1
  171. package/dist/mcp/config.d.ts +15 -2
  172. package/dist/mcp/config.d.ts.map +1 -1
  173. package/dist/mcp/config.js +50 -26
  174. package/dist/mcp/config.js.map +1 -1
  175. package/dist/mcp/fathom-cua.d.ts.map +1 -1
  176. package/dist/mcp/fathom-cua.js +10 -0
  177. package/dist/mcp/fathom-cua.js.map +1 -1
  178. package/dist/mcp/manager.d.ts.map +1 -1
  179. package/dist/mcp/manager.js +32 -1
  180. package/dist/mcp/manager.js.map +1 -1
  181. package/dist/mcp/tool-bridge.d.ts.map +1 -1
  182. package/dist/mcp/tool-bridge.js +12 -3
  183. package/dist/mcp/tool-bridge.js.map +1 -1
  184. package/dist/mcp/tool-capabilities.d.ts +5 -0
  185. package/dist/mcp/tool-capabilities.d.ts.map +1 -0
  186. package/dist/mcp/tool-capabilities.js +271 -0
  187. package/dist/mcp/tool-capabilities.js.map +1 -0
  188. package/dist/mcp/types.d.ts +6 -1
  189. package/dist/mcp/types.d.ts.map +1 -1
  190. package/dist/mcp/types.js.map +1 -1
  191. package/dist/models/config-loader.d.ts +1 -1
  192. package/dist/models/factory-integration.d.ts +1 -1
  193. package/dist/models/factory-integration.js +1 -1
  194. package/dist/models/factory-integration.js.map +1 -1
  195. package/dist/node_modules/@evalops/contracts/dist/index.d.ts +3 -3
  196. package/dist/node_modules/@evalops/contracts/dist/index.js +2 -2
  197. package/dist/node_modules/@evalops/contracts/dist/index.js.map +1 -1
  198. package/dist/node_modules/@evalops/contracts/dist/maestro-app-server.d.ts +1182 -14
  199. package/dist/node_modules/@evalops/contracts/dist/maestro-app-server.d.ts.map +1 -1
  200. package/dist/node_modules/@evalops/contracts/dist/maestro-app-server.js +450 -1
  201. package/dist/node_modules/@evalops/contracts/dist/maestro-app-server.js.map +1 -1
  202. package/dist/node_modules/@evalops/contracts/package.json +1 -1
  203. package/dist/node_modules/@evalops/tui/package.json +1 -1
  204. package/dist/oauth/connectors.d.ts +2 -2
  205. package/dist/oauth/connectors.d.ts.map +1 -1
  206. package/dist/oauth/connectors.js +3 -5
  207. package/dist/oauth/connectors.js.map +1 -1
  208. package/dist/oauth/github-copilot.d.ts +1 -1
  209. package/dist/oauth/github-copilot.js +1 -1
  210. package/dist/oauth/github-copilot.js.map +1 -1
  211. package/dist/oauth/index.d.ts +10 -8
  212. package/dist/oauth/index.d.ts.map +1 -1
  213. package/dist/oauth/index.js +54 -31
  214. package/dist/oauth/index.js.map +1 -1
  215. package/dist/oauth/openai.d.ts +1 -1
  216. package/dist/oauth/openai.js +2 -2
  217. package/dist/oauth/openai.js.map +1 -1
  218. package/dist/platform/a2a-completion-audit.d.ts +41 -0
  219. package/dist/platform/a2a-completion-audit.d.ts.map +1 -0
  220. package/dist/platform/a2a-completion-audit.js +177 -0
  221. package/dist/platform/a2a-completion-audit.js.map +1 -0
  222. package/dist/platform/a2a-task-ledger.d.ts.map +1 -1
  223. package/dist/platform/a2a-task-ledger.js +17 -0
  224. package/dist/platform/a2a-task-ledger.js.map +1 -1
  225. package/dist/platform/a2a-telemetry-inspect.d.ts +58 -0
  226. package/dist/platform/a2a-telemetry-inspect.d.ts.map +1 -0
  227. package/dist/platform/a2a-telemetry-inspect.js +224 -0
  228. package/dist/platform/a2a-telemetry-inspect.js.map +1 -0
  229. package/dist/platform/agent-registry-client.d.ts +8 -0
  230. package/dist/platform/agent-registry-client.d.ts.map +1 -1
  231. package/dist/platform/agent-registry-client.js +9 -1
  232. package/dist/platform/agent-registry-client.js.map +1 -1
  233. package/dist/providers/api-keys.d.ts +2 -2
  234. package/dist/providers/api-keys.js +2 -2
  235. package/dist/providers/api-keys.js.map +1 -1
  236. package/dist/providers/auth.d.ts +3 -6
  237. package/dist/providers/auth.d.ts.map +1 -1
  238. package/dist/providers/auth.js +1 -40
  239. package/dist/providers/auth.js.map +1 -1
  240. package/dist/rpc/index.d.ts +2 -2
  241. package/dist/rpc/index.js +2 -2
  242. package/dist/rpc/index.js.map +1 -1
  243. package/dist/rpc/rpc-types.d.ts +1 -1
  244. package/dist/rpc/rpc-types.js +1 -1
  245. package/dist/rpc/rpc-types.js.map +1 -1
  246. package/dist/safety/nested-agent-guard.js +1 -1
  247. package/dist/safety/nested-agent-guard.js.map +1 -1
  248. package/dist/safety/policy.d.ts +2 -2
  249. package/dist/safety/policy.js +2 -2
  250. package/dist/safety/policy.js.map +1 -1
  251. package/dist/safety/validators/network-policy-validator.d.ts +8 -0
  252. package/dist/safety/validators/network-policy-validator.d.ts.map +1 -1
  253. package/dist/safety/validators/network-policy-validator.js +29 -4
  254. package/dist/safety/validators/network-policy-validator.js.map +1 -1
  255. package/dist/sandbox/local-sandbox.d.ts +1 -1
  256. package/dist/sandbox/local-sandbox.js +1 -1
  257. package/dist/sandbox/local-sandbox.js.map +1 -1
  258. package/dist/server/app-context.d.ts +2 -0
  259. package/dist/server/app-context.d.ts.map +1 -1
  260. package/dist/server/app-context.js.map +1 -1
  261. package/dist/server/handlers/attachments.d.ts.map +1 -1
  262. package/dist/server/handlers/attachments.js +1 -0
  263. package/dist/server/handlers/attachments.js.map +1 -1
  264. package/dist/server/handlers/models.d.ts.map +1 -1
  265. package/dist/server/handlers/models.js +3 -1
  266. package/dist/server/handlers/models.js.map +1 -1
  267. package/dist/server/handlers/session-attachments.d.ts.map +1 -1
  268. package/dist/server/handlers/session-attachments.js +2 -0
  269. package/dist/server/handlers/session-attachments.js.map +1 -1
  270. package/dist/server/handlers/sessions.js +1 -1
  271. package/dist/server/handlers/sessions.js.map +1 -1
  272. package/dist/server/handlers/status.d.ts +2 -0
  273. package/dist/server/handlers/status.d.ts.map +1 -1
  274. package/dist/server/handlers/status.js +3 -2
  275. package/dist/server/handlers/status.js.map +1 -1
  276. package/dist/server/headless-runtime-service.d.ts.map +1 -1
  277. package/dist/server/headless-runtime-service.js +32 -3
  278. package/dist/server/headless-runtime-service.js.map +1 -1
  279. package/dist/server/hosted-session-manager.d.ts +2 -0
  280. package/dist/server/hosted-session-manager.d.ts.map +1 -1
  281. package/dist/server/hosted-session-manager.js +9 -0
  282. package/dist/server/hosted-session-manager.js.map +1 -1
  283. package/dist/server/model-selection.d.ts.map +1 -1
  284. package/dist/server/model-selection.js +9 -1
  285. package/dist/server/model-selection.js.map +1 -1
  286. package/dist/server/rate-limiter.d.ts +1 -1
  287. package/dist/server/rate-limiter.js +1 -1
  288. package/dist/server/rate-limiter.js.map +1 -1
  289. package/dist/server/router.d.ts +2 -2
  290. package/dist/server/router.js.map +1 -1
  291. package/dist/server/session-serialization.d.ts +9 -9
  292. package/dist/server/session-serialization.js +15 -15
  293. package/dist/server/session-serialization.js.map +1 -1
  294. package/dist/session/manager.d.ts +5 -0
  295. package/dist/session/manager.d.ts.map +1 -1
  296. package/dist/session/manager.js +56 -8
  297. package/dist/session/manager.js.map +1 -1
  298. package/dist/session/session-catalog.d.ts +2 -0
  299. package/dist/session/session-catalog.d.ts.map +1 -1
  300. package/dist/session/session-catalog.js +6 -0
  301. package/dist/session/session-catalog.js.map +1 -1
  302. package/dist/session/session-context.d.ts +2 -0
  303. package/dist/session/session-context.d.ts.map +1 -1
  304. package/dist/session/session-context.js +15 -0
  305. package/dist/session/session-context.js.map +1 -1
  306. package/dist/session/types.d.ts +7 -0
  307. package/dist/session/types.d.ts.map +1 -1
  308. package/dist/session/types.js.map +1 -1
  309. package/dist/session/wire-format.generated.d.ts +1 -0
  310. package/dist/session/wire-format.generated.d.ts.map +1 -1
  311. package/dist/session/wire-format.generated.js +1 -0
  312. package/dist/session/wire-format.generated.js.map +1 -1
  313. package/dist/shared-memory/contract.d.ts +4 -4
  314. package/dist/shared-memory/contract.js +2 -2
  315. package/dist/shared-memory/contract.js.map +1 -1
  316. package/dist/telemetry/index.d.ts +2 -2
  317. package/dist/telemetry/index.d.ts.map +1 -1
  318. package/dist/telemetry/index.js +2 -2
  319. package/dist/telemetry/index.js.map +1 -1
  320. package/dist/telemetry/maestro-event-bus.d.ts +57 -0
  321. package/dist/telemetry/maestro-event-bus.d.ts.map +1 -1
  322. package/dist/telemetry/maestro-event-bus.js +59 -1
  323. package/dist/telemetry/maestro-event-bus.js.map +1 -1
  324. package/dist/telemetry/maestro-event-catalog.d.ts +17 -1
  325. package/dist/telemetry/maestro-event-catalog.d.ts.map +1 -1
  326. package/dist/telemetry/maestro-event-catalog.js +24 -0
  327. package/dist/telemetry/maestro-event-catalog.js.map +1 -1
  328. package/dist/telemetry/mcp-beacon.d.ts +2 -0
  329. package/dist/telemetry/mcp-beacon.d.ts.map +1 -1
  330. package/dist/telemetry/mcp-beacon.js +15 -0
  331. package/dist/telemetry/mcp-beacon.js.map +1 -1
  332. package/dist/telemetry/metrics.d.ts +62 -0
  333. package/dist/telemetry/metrics.d.ts.map +1 -1
  334. package/dist/telemetry/metrics.js +84 -0
  335. package/dist/telemetry/metrics.js.map +1 -1
  336. package/dist/telemetry.d.ts +44 -0
  337. package/dist/telemetry.d.ts.map +1 -1
  338. package/dist/telemetry.js +84 -2
  339. package/dist/telemetry.js.map +1 -1
  340. package/dist/theme/theme-loader.js +2 -2
  341. package/dist/theme/theme-loader.js.map +1 -1
  342. package/dist/theme/theme-schema.json +2 -2
  343. package/dist/theme/theme.d.ts +1 -1
  344. package/dist/theme/theme.js.map +1 -1
  345. package/dist/tools/background/task-types.d.ts +1 -1
  346. package/dist/tools/extract-document.d.ts +1 -0
  347. package/dist/tools/extract-document.d.ts.map +1 -1
  348. package/dist/tools/extract-document.js +2 -1
  349. package/dist/tools/extract-document.js.map +1 -1
  350. package/dist/tools/index.d.ts +55 -55
  351. package/dist/tools/index.js +1 -1
  352. package/dist/tools/index.js.map +1 -1
  353. package/dist/tools/tool-dsl.d.ts +1 -1
  354. package/dist/tools/tool-dsl.js +1 -1
  355. package/dist/tools/tool-dsl.js.map +1 -1
  356. package/dist/utils/document-extractor.d.ts +1 -0
  357. package/dist/utils/document-extractor.d.ts.map +1 -1
  358. package/dist/utils/document-extractor.js +320 -40
  359. package/dist/utils/document-extractor.js.map +1 -1
  360. package/dist/utils/logger.d.ts +1 -1
  361. package/dist/utils/logger.js +1 -1
  362. package/dist/utils/logger.js.map +1 -1
  363. package/dist/version.json +2 -2
  364. package/dist/web-server.d.ts +1 -1
  365. package/dist/web-server.d.ts.map +1 -1
  366. package/dist/web-server.js +12 -8
  367. package/dist/web-server.js.map +1 -1
  368. package/package.json +4 -2
  369. package/dist/oauth/anthropic.d.ts +0 -17
  370. package/dist/oauth/anthropic.d.ts.map +0 -1
  371. package/dist/oauth/anthropic.js +0 -81
  372. package/dist/oauth/anthropic.js.map +0 -1
  373. package/dist/providers/anthropic-auth.d.ts +0 -75
  374. package/dist/providers/anthropic-auth.d.ts.map +0 -1
  375. package/dist/providers/anthropic-auth.js +0 -221
  376. package/dist/providers/anthropic-auth.js.map +0 -1
@@ -0,0 +1,219 @@
1
+ import { dirname, resolve } from "node:path";
2
+ import { addConfiguredPackageSpecToConfig, getWritablePackageConfigPath, loadConfiguredPackageSpecs, removeConfiguredPackageSpecFromConfig, } from "../config/toml-config.js";
3
+ import { parsePackageSpec } from "../packages/loader.js";
4
+ import { loadConfiguredPackageResources } from "../packages/runtime.js";
5
+ import { formatPackageSource, parsePackageSource, } from "../packages/sources.js";
6
+ export class MaestroAppServerPluginBundleError extends Error {
7
+ constructor(code, message) {
8
+ super(message);
9
+ this.code = code;
10
+ this.name = "MaestroAppServerPluginBundleError";
11
+ }
12
+ }
13
+ function isRecord(value) {
14
+ return typeof value === "object" && value !== null && !Array.isArray(value);
15
+ }
16
+ function stringValue(value) {
17
+ return typeof value === "string" && value.trim() ? value.trim() : undefined;
18
+ }
19
+ function booleanValue(value, fallback) {
20
+ return typeof value === "boolean" ? value : fallback;
21
+ }
22
+ function paramsRecord(params) {
23
+ if (params === undefined) {
24
+ return {};
25
+ }
26
+ if (isRecord(params)) {
27
+ return params;
28
+ }
29
+ throw new MaestroAppServerPluginBundleError(-32602, "Invalid params");
30
+ }
31
+ function projectRootFromParams(params, options) {
32
+ return resolve(stringValue(params.projectRoot) ?? options.projectRoot ?? process.cwd());
33
+ }
34
+ function scopeFromParams(params) {
35
+ const scope = stringValue(params.scope);
36
+ if (scope === "project" || scope === "local" || scope === "user") {
37
+ return scope;
38
+ }
39
+ if (scope !== undefined) {
40
+ throw new MaestroAppServerPluginBundleError(-32602, "Invalid plugin bundle scope");
41
+ }
42
+ return "local";
43
+ }
44
+ function packageSpecFromParams(params) {
45
+ const spec = params.spec ?? params.source;
46
+ if (typeof spec === "string" && spec.trim()) {
47
+ return spec.trim();
48
+ }
49
+ if (isRecord(spec) && typeof spec.source === "string" && spec.source.trim()) {
50
+ return spec;
51
+ }
52
+ throw new MaestroAppServerPluginBundleError(-32602, "Plugin bundle requires source or spec");
53
+ }
54
+ function sourceString(spec) {
55
+ return typeof spec === "string" ? spec : spec.source;
56
+ }
57
+ function resolvePackageSpecIdentity(spec, cwd) {
58
+ const [sourceSpec] = parsePackageSpec(spec, cwd);
59
+ return formatPackageSource(parsePackageSource(sourceSpec, cwd));
60
+ }
61
+ function tryResolvePackageSourceIdentity(sourceSpec, cwd) {
62
+ try {
63
+ return formatPackageSource(parsePackageSource(sourceSpec, cwd));
64
+ }
65
+ catch {
66
+ return null;
67
+ }
68
+ }
69
+ function configuredPackageMatches(entry, requestedSpec, requestedCwd) {
70
+ const [rawSourceSpec] = parsePackageSpec(entry.spec, entry.cwd);
71
+ if (rawSourceSpec === requestedSpec) {
72
+ return true;
73
+ }
74
+ const requestedIdentity = tryResolvePackageSourceIdentity(requestedSpec, requestedCwd);
75
+ if (!requestedIdentity) {
76
+ return false;
77
+ }
78
+ return (resolvePackageSpecIdentity(entry.spec, entry.cwd) === requestedIdentity);
79
+ }
80
+ function validateBundleInstall(projectRoot, scope, spec) {
81
+ const configPath = getWritablePackageConfigPath(scope, projectRoot);
82
+ const configDir = dirname(configPath);
83
+ const requestedIdentity = resolvePackageSpecIdentity(spec, projectRoot);
84
+ const duplicate = loadConfiguredPackageSpecs(projectRoot).find((entry) => entry.configPath === configPath &&
85
+ resolvePackageSpecIdentity(entry.spec, configDir) === requestedIdentity);
86
+ if (duplicate) {
87
+ const [sourceSpec] = parsePackageSpec(duplicate.spec, configDir);
88
+ throw new MaestroAppServerPluginBundleError(-32602, `Package "${sourceSpec}" already exists in ${configPath}.`);
89
+ }
90
+ return { configPath };
91
+ }
92
+ function resolveBundleRemoval(projectRoot, spec, scope) {
93
+ const requestedSpec = sourceString(spec);
94
+ const matches = loadConfiguredPackageSpecs(projectRoot).filter((entry) => (scope === undefined || entry.scope === scope) &&
95
+ configuredPackageMatches(entry, requestedSpec, projectRoot));
96
+ const orderedScopes = scope === undefined ? ["local", "project", "user"] : [scope];
97
+ for (const candidateScope of orderedScopes) {
98
+ const match = matches.find((entry) => entry.scope === candidateScope);
99
+ if (match) {
100
+ return { configPath: match.configPath, scope: match.scope };
101
+ }
102
+ }
103
+ const scopeMessage = scope === undefined ? "" : ` in ${scope} config`;
104
+ throw new MaestroAppServerPluginBundleError(-32602, `Configured package "${requestedSpec}" was not found${scopeMessage}.`);
105
+ }
106
+ function toBundleScope(scope) {
107
+ return scope;
108
+ }
109
+ function pluginBundleErrorMessage(error) {
110
+ return error instanceof Error ? error.message : String(error);
111
+ }
112
+ function toPluginBundleInvalidParams(error) {
113
+ if (error instanceof MaestroAppServerPluginBundleError) {
114
+ return error;
115
+ }
116
+ return new MaestroAppServerPluginBundleError(-32602, pluginBundleErrorMessage(error));
117
+ }
118
+ export function createMaestroAppServerPluginBundleApi(options = {}) {
119
+ return {
120
+ async listBundles(params = {}) {
121
+ const normalizedParams = paramsRecord(params);
122
+ const projectRoot = projectRootFromParams(normalizedParams, options);
123
+ const resources = loadConfiguredPackageResources(projectRoot);
124
+ return {
125
+ bundles: loadConfiguredPackageSpecs(projectRoot).map((entry) => ({
126
+ source: sourceString(entry.spec),
127
+ scope: toBundleScope(entry.scope),
128
+ configPath: entry.configPath,
129
+ })),
130
+ resources: {
131
+ extensions: resources.extensions,
132
+ skills: resources.skills,
133
+ prompts: resources.prompts,
134
+ themes: resources.themes,
135
+ },
136
+ errors: resources.errors,
137
+ };
138
+ },
139
+ async installBundle(params = {}) {
140
+ const normalizedParams = paramsRecord(params);
141
+ const projectRoot = projectRootFromParams(normalizedParams, options);
142
+ const spec = packageSpecFromParams(normalizedParams);
143
+ const source = sourceString(spec);
144
+ const scope = scopeFromParams(normalizedParams);
145
+ let validation;
146
+ try {
147
+ validation = validateBundleInstall(projectRoot, scope, spec);
148
+ }
149
+ catch (error) {
150
+ throw toPluginBundleInvalidParams(error);
151
+ }
152
+ const { configPath } = validation;
153
+ if (booleanValue(normalizedParams.dryRun, false)) {
154
+ return {
155
+ source,
156
+ scope,
157
+ configPath,
158
+ changed: false,
159
+ message: "Plugin bundle install planned",
160
+ };
161
+ }
162
+ let result;
163
+ try {
164
+ result = addConfiguredPackageSpecToConfig({
165
+ workspaceDir: projectRoot,
166
+ scope,
167
+ spec,
168
+ });
169
+ }
170
+ catch (error) {
171
+ throw toPluginBundleInvalidParams(error);
172
+ }
173
+ return {
174
+ source,
175
+ scope: result.scope,
176
+ configPath: result.path,
177
+ changed: true,
178
+ message: "Plugin bundle installed",
179
+ };
180
+ },
181
+ async removeBundle(params = {}) {
182
+ const normalizedParams = paramsRecord(params);
183
+ const projectRoot = projectRootFromParams(normalizedParams, options);
184
+ const spec = packageSpecFromParams(normalizedParams);
185
+ const scope = normalizedParams.scope === undefined
186
+ ? undefined
187
+ : scopeFromParams(normalizedParams);
188
+ const removal = resolveBundleRemoval(projectRoot, spec, scope);
189
+ if (booleanValue(normalizedParams.dryRun, false)) {
190
+ return {
191
+ source: sourceString(spec),
192
+ scope: removal.scope,
193
+ configPath: removal.configPath,
194
+ changed: false,
195
+ message: "Plugin bundle removal planned",
196
+ };
197
+ }
198
+ let result;
199
+ try {
200
+ result = removeConfiguredPackageSpecFromConfig({
201
+ workspaceDir: projectRoot,
202
+ scope,
203
+ spec: sourceString(spec),
204
+ });
205
+ }
206
+ catch (error) {
207
+ throw new MaestroAppServerPluginBundleError(-32602, pluginBundleErrorMessage(error));
208
+ }
209
+ return {
210
+ source: sourceString(spec),
211
+ scope: result.scope,
212
+ configPath: result.path,
213
+ changed: result.removedCount > 0,
214
+ message: `Removed ${result.removedCount} plugin bundle(s)`,
215
+ };
216
+ },
217
+ };
218
+ }
219
+ //# sourceMappingURL=plugin-bundle-api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin-bundle-api.js","sourceRoot":"","sources":["../../src/app-server/plugin-bundle-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAM7C,OAAO,EAEN,gCAAgC,EAChC,4BAA4B,EAC5B,0BAA0B,EAC1B,qCAAqC,GACr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CAAC,IAAI,CAAC;gBAC1B,KAAK,EAAE,MAAM,CAAC,KAAK;gBACnB,UAAU,EAAE,MAAM,CAAC,IAAI;gBACvB,OAAO,EAAE,MAAM,CAAC,YAAY,GAAG,CAAC;gBAChC,OAAO,EAAE,WAAW,MAAM,CAAC,YAAY,mBAAmB;aAC1D,CAAC;QACH,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["import { dirname, resolve } from \"node:path\";\nimport type {\n\tMaestroAppServerPluginBundleListResult,\n\tMaestroAppServerPluginBundleMutationResult,\n\tMaestroAppServerPluginBundleScope,\n} from \"@evalops/contracts\";\nimport {\n\ttype WritablePackageScope,\n\taddConfiguredPackageSpecToConfig,\n\tgetWritablePackageConfigPath,\n\tloadConfiguredPackageSpecs,\n\tremoveConfiguredPackageSpecFromConfig,\n} from \"../config/toml-config.js\";\nimport { parsePackageSpec } from \"../packages/loader.js\";\nimport { loadConfiguredPackageResources } from \"../packages/runtime.js\";\nimport {\n\tformatPackageSource,\n\tparsePackageSource,\n} from \"../packages/sources.js\";\nimport type { PackageSpec } from \"../packages/types.js\";\n\ntype UnknownRecord = Record<string, unknown>;\n\nexport class MaestroAppServerPluginBundleError extends Error {\n\tconstructor(\n\t\treadonly code: number,\n\t\tmessage: string,\n\t) {\n\t\tsuper(message);\n\t\tthis.name = \"MaestroAppServerPluginBundleError\";\n\t}\n}\n\nexport interface MaestroAppServerPluginBundleApi {\n\tlistBundles(\n\t\tparams?: UnknownRecord,\n\t): Promise<MaestroAppServerPluginBundleListResult>;\n\tinstallBundle(\n\t\tparams?: UnknownRecord,\n\t): Promise<MaestroAppServerPluginBundleMutationResult>;\n\tremoveBundle(\n\t\tparams?: UnknownRecord,\n\t): Promise<MaestroAppServerPluginBundleMutationResult>;\n}\n\nexport interface MaestroAppServerPluginBundleApiOptions {\n\tprojectRoot?: string;\n}\n\nfunction isRecord(value: unknown): value is UnknownRecord {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction stringValue(value: unknown): string | undefined {\n\treturn typeof value === \"string\" && value.trim() ? value.trim() : undefined;\n}\n\nfunction booleanValue(value: unknown, fallback: boolean): boolean {\n\treturn typeof value === \"boolean\" ? value : fallback;\n}\n\nfunction paramsRecord(params: unknown): UnknownRecord {\n\tif (params === undefined) {\n\t\treturn {};\n\t}\n\tif (isRecord(params)) {\n\t\treturn params;\n\t}\n\tthrow new MaestroAppServerPluginBundleError(-32602, \"Invalid params\");\n}\n\nfunction projectRootFromParams(\n\tparams: UnknownRecord,\n\toptions: MaestroAppServerPluginBundleApiOptions,\n): string {\n\treturn resolve(\n\t\tstringValue(params.projectRoot) ?? options.projectRoot ?? process.cwd(),\n\t);\n}\n\nfunction scopeFromParams(params: UnknownRecord): WritablePackageScope {\n\tconst scope = stringValue(params.scope);\n\tif (scope === \"project\" || scope === \"local\" || scope === \"user\") {\n\t\treturn scope;\n\t}\n\tif (scope !== undefined) {\n\t\tthrow new MaestroAppServerPluginBundleError(\n\t\t\t-32602,\n\t\t\t\"Invalid plugin bundle scope\",\n\t\t);\n\t}\n\treturn \"local\";\n}\n\nfunction packageSpecFromParams(params: UnknownRecord): PackageSpec {\n\tconst spec = params.spec ?? params.source;\n\tif (typeof spec === \"string\" && spec.trim()) {\n\t\treturn spec.trim();\n\t}\n\tif (isRecord(spec) && typeof spec.source === \"string\" && spec.source.trim()) {\n\t\treturn spec as unknown as PackageSpec;\n\t}\n\tthrow new MaestroAppServerPluginBundleError(\n\t\t-32602,\n\t\t\"Plugin bundle requires source or spec\",\n\t);\n}\n\nfunction sourceString(spec: PackageSpec): string {\n\treturn typeof spec === \"string\" ? spec : spec.source;\n}\n\nfunction resolvePackageSpecIdentity(spec: PackageSpec, cwd: string): string {\n\tconst [sourceSpec] = parsePackageSpec(spec, cwd);\n\treturn formatPackageSource(parsePackageSource(sourceSpec, cwd));\n}\n\nfunction tryResolvePackageSourceIdentity(\n\tsourceSpec: string,\n\tcwd: string,\n): string | null {\n\ttry {\n\t\treturn formatPackageSource(parsePackageSource(sourceSpec, cwd));\n\t} catch {\n\t\treturn null;\n\t}\n}\n\nfunction configuredPackageMatches(\n\tentry: ReturnType<typeof loadConfiguredPackageSpecs>[number],\n\trequestedSpec: string,\n\trequestedCwd: string,\n): boolean {\n\tconst [rawSourceSpec] = parsePackageSpec(entry.spec, entry.cwd);\n\tif (rawSourceSpec === requestedSpec) {\n\t\treturn true;\n\t}\n\tconst requestedIdentity = tryResolvePackageSourceIdentity(\n\t\trequestedSpec,\n\t\trequestedCwd,\n\t);\n\tif (!requestedIdentity) {\n\t\treturn false;\n\t}\n\treturn (\n\t\tresolvePackageSpecIdentity(entry.spec, entry.cwd) === requestedIdentity\n\t);\n}\n\nfunction validateBundleInstall(\n\tprojectRoot: string,\n\tscope: WritablePackageScope,\n\tspec: PackageSpec,\n): { configPath: string } {\n\tconst configPath = getWritablePackageConfigPath(scope, projectRoot);\n\tconst configDir = dirname(configPath);\n\tconst requestedIdentity = resolvePackageSpecIdentity(spec, projectRoot);\n\tconst duplicate = loadConfiguredPackageSpecs(projectRoot).find(\n\t\t(entry) =>\n\t\t\tentry.configPath === configPath &&\n\t\t\tresolvePackageSpecIdentity(entry.spec, configDir) === requestedIdentity,\n\t);\n\tif (duplicate) {\n\t\tconst [sourceSpec] = parsePackageSpec(duplicate.spec, configDir);\n\t\tthrow new MaestroAppServerPluginBundleError(\n\t\t\t-32602,\n\t\t\t`Package \"${sourceSpec}\" already exists in ${configPath}.`,\n\t\t);\n\t}\n\treturn { configPath };\n}\n\nfunction resolveBundleRemoval(\n\tprojectRoot: string,\n\tspec: PackageSpec,\n\tscope?: WritablePackageScope,\n): { configPath: string; scope: WritablePackageScope } {\n\tconst requestedSpec = sourceString(spec);\n\tconst matches = loadConfiguredPackageSpecs(projectRoot).filter(\n\t\t(entry) =>\n\t\t\t(scope === undefined || entry.scope === scope) &&\n\t\t\tconfiguredPackageMatches(entry, requestedSpec, projectRoot),\n\t);\n\tconst orderedScopes: WritablePackageScope[] =\n\t\tscope === undefined ? [\"local\", \"project\", \"user\"] : [scope];\n\tfor (const candidateScope of orderedScopes) {\n\t\tconst match = matches.find((entry) => entry.scope === candidateScope);\n\t\tif (match) {\n\t\t\treturn { configPath: match.configPath, scope: match.scope };\n\t\t}\n\t}\n\tconst scopeMessage = scope === undefined ? \"\" : ` in ${scope} config`;\n\tthrow new MaestroAppServerPluginBundleError(\n\t\t-32602,\n\t\t`Configured package \"${requestedSpec}\" was not found${scopeMessage}.`,\n\t);\n}\n\nfunction toBundleScope(\n\tscope: WritablePackageScope,\n): MaestroAppServerPluginBundleScope {\n\treturn scope;\n}\n\nfunction pluginBundleErrorMessage(error: unknown): string {\n\treturn error instanceof Error ? error.message : String(error);\n}\n\nfunction toPluginBundleInvalidParams(\n\terror: unknown,\n): MaestroAppServerPluginBundleError {\n\tif (error instanceof MaestroAppServerPluginBundleError) {\n\t\treturn error;\n\t}\n\treturn new MaestroAppServerPluginBundleError(\n\t\t-32602,\n\t\tpluginBundleErrorMessage(error),\n\t);\n}\n\nexport function createMaestroAppServerPluginBundleApi(\n\toptions: MaestroAppServerPluginBundleApiOptions = {},\n): MaestroAppServerPluginBundleApi {\n\treturn {\n\t\tasync listBundles(params = {}) {\n\t\t\tconst normalizedParams = paramsRecord(params);\n\t\t\tconst projectRoot = projectRootFromParams(normalizedParams, options);\n\t\t\tconst resources = loadConfiguredPackageResources(projectRoot);\n\t\t\treturn {\n\t\t\t\tbundles: loadConfiguredPackageSpecs(projectRoot).map((entry) => ({\n\t\t\t\t\tsource: sourceString(entry.spec),\n\t\t\t\t\tscope: toBundleScope(entry.scope),\n\t\t\t\t\tconfigPath: entry.configPath,\n\t\t\t\t})),\n\t\t\t\tresources: {\n\t\t\t\t\textensions: resources.extensions,\n\t\t\t\t\tskills: resources.skills,\n\t\t\t\t\tprompts: resources.prompts,\n\t\t\t\t\tthemes: resources.themes,\n\t\t\t\t},\n\t\t\t\terrors: resources.errors,\n\t\t\t};\n\t\t},\n\n\t\tasync installBundle(params = {}) {\n\t\t\tconst normalizedParams = paramsRecord(params);\n\t\t\tconst projectRoot = projectRootFromParams(normalizedParams, options);\n\t\t\tconst spec = packageSpecFromParams(normalizedParams);\n\t\t\tconst source = sourceString(spec);\n\t\t\tconst scope = scopeFromParams(normalizedParams);\n\t\t\tlet validation: ReturnType<typeof validateBundleInstall>;\n\t\t\ttry {\n\t\t\t\tvalidation = validateBundleInstall(projectRoot, scope, spec);\n\t\t\t} catch (error) {\n\t\t\t\tthrow toPluginBundleInvalidParams(error);\n\t\t\t}\n\t\t\tconst { configPath } = validation;\n\t\t\tif (booleanValue(normalizedParams.dryRun, false)) {\n\t\t\t\treturn {\n\t\t\t\t\tsource,\n\t\t\t\t\tscope,\n\t\t\t\t\tconfigPath,\n\t\t\t\t\tchanged: false,\n\t\t\t\t\tmessage: \"Plugin bundle install planned\",\n\t\t\t\t};\n\t\t\t}\n\t\t\tlet result: ReturnType<typeof addConfiguredPackageSpecToConfig>;\n\t\t\ttry {\n\t\t\t\tresult = addConfiguredPackageSpecToConfig({\n\t\t\t\t\tworkspaceDir: projectRoot,\n\t\t\t\t\tscope,\n\t\t\t\t\tspec,\n\t\t\t\t});\n\t\t\t} catch (error) {\n\t\t\t\tthrow toPluginBundleInvalidParams(error);\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tsource,\n\t\t\t\tscope: result.scope,\n\t\t\t\tconfigPath: result.path,\n\t\t\t\tchanged: true,\n\t\t\t\tmessage: \"Plugin bundle installed\",\n\t\t\t};\n\t\t},\n\n\t\tasync removeBundle(params = {}) {\n\t\t\tconst normalizedParams = paramsRecord(params);\n\t\t\tconst projectRoot = projectRootFromParams(normalizedParams, options);\n\t\t\tconst spec = packageSpecFromParams(normalizedParams);\n\t\t\tconst scope =\n\t\t\t\tnormalizedParams.scope === undefined\n\t\t\t\t\t? undefined\n\t\t\t\t\t: scopeFromParams(normalizedParams);\n\t\t\tconst removal = resolveBundleRemoval(projectRoot, spec, scope);\n\t\t\tif (booleanValue(normalizedParams.dryRun, false)) {\n\t\t\t\treturn {\n\t\t\t\t\tsource: sourceString(spec),\n\t\t\t\t\tscope: removal.scope,\n\t\t\t\t\tconfigPath: removal.configPath,\n\t\t\t\t\tchanged: false,\n\t\t\t\t\tmessage: \"Plugin bundle removal planned\",\n\t\t\t\t};\n\t\t\t}\n\t\t\tlet result: ReturnType<typeof removeConfiguredPackageSpecFromConfig>;\n\t\t\ttry {\n\t\t\t\tresult = removeConfiguredPackageSpecFromConfig({\n\t\t\t\t\tworkspaceDir: projectRoot,\n\t\t\t\t\tscope,\n\t\t\t\t\tspec: sourceString(spec),\n\t\t\t\t});\n\t\t\t} catch (error) {\n\t\t\t\tthrow new MaestroAppServerPluginBundleError(\n\t\t\t\t\t-32602,\n\t\t\t\t\tpluginBundleErrorMessage(error),\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tsource: sourceString(spec),\n\t\t\t\tscope: result.scope,\n\t\t\t\tconfigPath: result.path,\n\t\t\t\tchanged: result.removedCount > 0,\n\t\t\t\tmessage: `Removed ${result.removedCount} plugin bundle(s)`,\n\t\t\t};\n\t\t},\n\t};\n}\n"]}
@@ -0,0 +1,14 @@
1
+ import type { MaestroAppServerPolicyCheckResult, MaestroAppServerPolicyReadResult, MaestroAppServerRequirementsListResult } from "@evalops/contracts";
2
+ type UnknownRecord = Record<string, unknown>;
3
+ export declare class MaestroAppServerPolicyControlError extends Error {
4
+ readonly code: number;
5
+ constructor(code: number, message: string);
6
+ }
7
+ export interface MaestroAppServerPolicyControl {
8
+ readPolicy(): MaestroAppServerPolicyReadResult;
9
+ checkPolicy(params?: UnknownRecord): Promise<MaestroAppServerPolicyCheckResult>;
10
+ listRequirements(): MaestroAppServerRequirementsListResult;
11
+ }
12
+ export declare function createMaestroAppServerPolicyControl(): MaestroAppServerPolicyControl;
13
+ export {};
14
+ //# sourceMappingURL=policy-control-api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"policy-control-api.d.ts","sourceRoot":"","sources":["../../src/app-server/policy-control-api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEX,iCAAiC,EACjC,gCAAgC,EAChC,sCAAsC,EACtC,MAAM,oBAAoB,CAAC;AAU5B,KAAK,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAE7C,qBAAa,kCAAmC,SAAQ,KAAK;IAE3D,QAAQ,CAAC,IAAI,EAAE,MAAM;gBAAZ,IAAI,EAAE,MAAM,EACrB,OAAO,EAAE,MAAM;CAKhB;AAED,MAAM,WAAW,6BAA6B;IAC7C,UAAU,IAAI,gCAAgC,CAAC;IAC/C,WAAW,CACV,MAAM,CAAC,EAAE,aAAa,GACpB,OAAO,CAAC,iCAAiC,CAAC,CAAC;IAC9C,gBAAgB,IAAI,sCAAsC,CAAC;CAC3D;AA2KD,wBAAgB,mCAAmC,IAAI,6BAA6B,CA+EnF"}
@@ -0,0 +1,200 @@
1
+ import { checkModelPolicy, checkPolicy, checkSessionLimits, loadPolicy, } from "../safety/policy.js";
2
+ export class MaestroAppServerPolicyControlError extends Error {
3
+ constructor(code, message) {
4
+ super(message);
5
+ this.code = code;
6
+ this.name = "MaestroAppServerPolicyControlError";
7
+ }
8
+ }
9
+ function readCurrentPolicy() {
10
+ try {
11
+ return loadPolicy();
12
+ }
13
+ catch (error) {
14
+ throw new MaestroAppServerPolicyControlError(-32000, `Failed to load managed policy: ${error instanceof Error ? error.message : "unknown error"}`);
15
+ }
16
+ }
17
+ function deepFreezeSnapshot(value) {
18
+ if (typeof value !== "object" || value === null) {
19
+ return value;
20
+ }
21
+ for (const key of Object.getOwnPropertyNames(value)) {
22
+ deepFreezeSnapshot(value[key]);
23
+ }
24
+ return Object.freeze(value);
25
+ }
26
+ function clonePolicySnapshot(policy) {
27
+ if (policy === null) {
28
+ return null;
29
+ }
30
+ return deepFreezeSnapshot(structuredClone(policy));
31
+ }
32
+ function isRecord(value) {
33
+ return typeof value === "object" && value !== null && !Array.isArray(value);
34
+ }
35
+ function hasOwnKey(value, key) {
36
+ return Object.prototype.hasOwnProperty.call(value, key);
37
+ }
38
+ function optionalNonEmptyString(value, field) {
39
+ if (value === undefined || value === null) {
40
+ return undefined;
41
+ }
42
+ if (typeof value !== "string" || value.trim().length === 0) {
43
+ throw new MaestroAppServerPolicyControlError(-32602, `Invalid ${field}`);
44
+ }
45
+ return value.trim();
46
+ }
47
+ function parseUser(value) {
48
+ if (value === undefined || value === null) {
49
+ return undefined;
50
+ }
51
+ if (!isRecord(value)) {
52
+ throw new MaestroAppServerPolicyControlError(-32602, "Invalid user");
53
+ }
54
+ const id = optionalNonEmptyString(value.id, "user.id");
55
+ const orgId = optionalNonEmptyString(value.orgId, "user.orgId");
56
+ if (!id || !orgId) {
57
+ throw new MaestroAppServerPolicyControlError(-32602, "Invalid user");
58
+ }
59
+ return { id, orgId };
60
+ }
61
+ function parseSession(value, requireId) {
62
+ if (value === undefined || value === null) {
63
+ return undefined;
64
+ }
65
+ if (!isRecord(value)) {
66
+ throw new MaestroAppServerPolicyControlError(-32602, "Invalid session");
67
+ }
68
+ const id = optionalNonEmptyString(value.id, "session.id");
69
+ if (requireId && !id) {
70
+ throw new MaestroAppServerPolicyControlError(-32602, "Invalid session.id");
71
+ }
72
+ if (value.startedAt === undefined || value.startedAt === null) {
73
+ throw new MaestroAppServerPolicyControlError(-32602, "Invalid session.startedAt");
74
+ }
75
+ const startedAt = value.startedAt instanceof Date
76
+ ? new Date(value.startedAt.getTime())
77
+ : new Date(optionalNonEmptyString(value.startedAt, "session.startedAt") ?? "");
78
+ if (!Number.isFinite(startedAt.getTime())) {
79
+ throw new MaestroAppServerPolicyControlError(-32602, "Invalid session.startedAt");
80
+ }
81
+ return { id: id ?? "app-server-policy-check", startedAt };
82
+ }
83
+ function parseActionContext(value, fallbackSession) {
84
+ if (value === undefined || value === null) {
85
+ return undefined;
86
+ }
87
+ if (!isRecord(value)) {
88
+ throw new MaestroAppServerPolicyControlError(-32602, "Invalid action");
89
+ }
90
+ const toolName = optionalNonEmptyString(value.toolName, "action.toolName");
91
+ if (!toolName) {
92
+ throw new MaestroAppServerPolicyControlError(-32602, "Invalid action.toolName");
93
+ }
94
+ const actionSession = value.session === undefined || value.session === null
95
+ ? fallbackSession
96
+ : parseSession(value.session, false);
97
+ return {
98
+ toolName,
99
+ args: hasOwnKey(value, "args") ? value.args : {},
100
+ metadata: isRecord(value.metadata)
101
+ ? value.metadata
102
+ : undefined,
103
+ user: parseUser(value.user),
104
+ session: actionSession,
105
+ userIntent: optionalNonEmptyString(value.userIntent, "action.userIntent"),
106
+ };
107
+ }
108
+ function parseUsage(value) {
109
+ if (value === undefined || value === null) {
110
+ return undefined;
111
+ }
112
+ if (!isRecord(value)) {
113
+ throw new MaestroAppServerPolicyControlError(-32602, "Invalid usage");
114
+ }
115
+ const usage = {};
116
+ for (const key of ["tokenCount", "activeSessionCount"]) {
117
+ if (value[key] === undefined || value[key] === null) {
118
+ continue;
119
+ }
120
+ if (typeof value[key] !== "number" ||
121
+ !Number.isFinite(value[key]) ||
122
+ value[key] < 0) {
123
+ throw new MaestroAppServerPolicyControlError(-32602, `Invalid usage.${key}`);
124
+ }
125
+ usage[key] = value[key];
126
+ }
127
+ return usage;
128
+ }
129
+ function firstReason(checks) {
130
+ return checks.find((check) => !check.allowed)?.reason;
131
+ }
132
+ export function createMaestroAppServerPolicyControl() {
133
+ return {
134
+ readPolicy() {
135
+ const policy = readCurrentPolicy();
136
+ return {
137
+ loaded: policy !== null,
138
+ policy: clonePolicySnapshot(policy),
139
+ };
140
+ },
141
+ async checkPolicy(params = {}) {
142
+ if (!isRecord(params)) {
143
+ throw new MaestroAppServerPolicyControlError(-32602, "Invalid params");
144
+ }
145
+ const checks = [];
146
+ const session = parseSession(params.session, false);
147
+ const action = parseActionContext(params.action, session);
148
+ const sessionForLimits = action?.session ?? session;
149
+ if (action) {
150
+ const result = await checkPolicy(action);
151
+ checks.push({
152
+ kind: "action",
153
+ allowed: result.allowed,
154
+ ...(result.reason ? { reason: result.reason } : {}),
155
+ });
156
+ }
157
+ const modelId = optionalNonEmptyString(params.modelId, "modelId");
158
+ if (modelId) {
159
+ const result = checkModelPolicy(modelId);
160
+ checks.push({
161
+ kind: "model",
162
+ allowed: result.allowed,
163
+ ...(result.reason ? { reason: result.reason } : {}),
164
+ });
165
+ }
166
+ if (sessionForLimits) {
167
+ const result = checkSessionLimits(sessionForLimits, parseUsage(params.usage));
168
+ checks.push({
169
+ kind: "session",
170
+ allowed: result.allowed,
171
+ ...(result.reason ? { reason: result.reason } : {}),
172
+ });
173
+ }
174
+ if (checks.length === 0) {
175
+ throw new MaestroAppServerPolicyControlError(-32602, "Missing policy check target");
176
+ }
177
+ const reason = firstReason(checks);
178
+ return {
179
+ allowed: checks.every((check) => check.allowed),
180
+ ...(reason ? { reason } : {}),
181
+ checks,
182
+ };
183
+ },
184
+ listRequirements() {
185
+ const policy = readCurrentPolicy();
186
+ const requiredSkills = deepFreezeSnapshot([
187
+ ...(policy?.skills?.required ?? []),
188
+ ]);
189
+ return {
190
+ requirements: requiredSkills.map((id) => ({
191
+ kind: "skill",
192
+ id,
193
+ required: true,
194
+ })),
195
+ requiredSkills,
196
+ };
197
+ },
198
+ };
199
+ }
200
+ //# sourceMappingURL=policy-control-api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"policy-control-api.js","sourceRoot":"","sources":["../../src/app-server/policy-control-api.ts"],"names":[],"mappings":"AAOA,OAAO,EAEN,gBAAgB,EAChB,WAAW,EACX,kBAAkB,EAClB,UAAU,GACV,MAAM,qBAAqB,CAAC;AAI7B,MAAM,OAAO,kCAAmC,SAAQ,KAAK;IAC5D,YACU,IAAY,EACrB,OAAe;QAEf,KAAK,CAAC,OAAO,CAAC,CAAC;QAHN,SAAI,GAAJ,IAAI,CAAQ;QAIrB,IAAI,CAAC,IAAI,GAAG,oCAAoC,CAAC;IAClD,CAAC;CACD;AAUD,SAAS,iBAAiB;IACzB,IAAI,CAAC;QACJ,OAAO,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CAAC;YACnC,OAAO;gBACN,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC;gBAC/C,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBAC7B,MAAM;aACN,CAAC;QACH,CAAC;QAED,gBAAgB;YACf,MAAM,MAAM,GAAG,iBAAiB,EAAE,CAAC;YACnC,MAAM,cAAc,GAAG,kBAAkB,CAAC;gBACzC,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,IAAI,EAAE,CAAC;aACnC,CAAC,CAAC;YACH,OAAO;gBACN,YAAY,EAAE,cAAc,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;oBACzC,IAAI,EAAE,OAAO;oBACb,EAAE;oBACF,QAAQ,EAAE,IAAI;iBACd,CAAC,CAAC;gBACH,cAAc;aACd,CAAC;QACH,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["import type {\n\tMaestroAppServerPolicyCheckItem,\n\tMaestroAppServerPolicyCheckResult,\n\tMaestroAppServerPolicyReadResult,\n\tMaestroAppServerRequirementsListResult,\n} from \"@evalops/contracts\";\nimport type { ActionApprovalContext } from \"../agent/action-approval.js\";\nimport {\n\ttype EnterprisePolicy,\n\tcheckModelPolicy,\n\tcheckPolicy,\n\tcheckSessionLimits,\n\tloadPolicy,\n} from \"../safety/policy.js\";\n\ntype UnknownRecord = Record<string, unknown>;\n\nexport class MaestroAppServerPolicyControlError extends Error {\n\tconstructor(\n\t\treadonly code: number,\n\t\tmessage: string,\n\t) {\n\t\tsuper(message);\n\t\tthis.name = \"MaestroAppServerPolicyControlError\";\n\t}\n}\n\nexport interface MaestroAppServerPolicyControl {\n\treadPolicy(): MaestroAppServerPolicyReadResult;\n\tcheckPolicy(\n\t\tparams?: UnknownRecord,\n\t): Promise<MaestroAppServerPolicyCheckResult>;\n\tlistRequirements(): MaestroAppServerRequirementsListResult;\n}\n\nfunction readCurrentPolicy() {\n\ttry {\n\t\treturn loadPolicy();\n\t} catch (error) {\n\t\tthrow new MaestroAppServerPolicyControlError(\n\t\t\t-32000,\n\t\t\t`Failed to load managed policy: ${error instanceof Error ? error.message : \"unknown error\"}`,\n\t\t);\n\t}\n}\n\nfunction deepFreezeSnapshot<T>(value: T): T {\n\tif (typeof value !== \"object\" || value === null) {\n\t\treturn value;\n\t}\n\tfor (const key of Object.getOwnPropertyNames(value)) {\n\t\tdeepFreezeSnapshot((value as Record<string, unknown>)[key]);\n\t}\n\treturn Object.freeze(value);\n}\n\nfunction clonePolicySnapshot(\n\tpolicy: EnterprisePolicy | null,\n): MaestroAppServerPolicyReadResult[\"policy\"] {\n\tif (policy === null) {\n\t\treturn null;\n\t}\n\treturn deepFreezeSnapshot(structuredClone(policy));\n}\n\nfunction isRecord(value: unknown): value is UnknownRecord {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction hasOwnKey(value: object, key: PropertyKey): boolean {\n\treturn Object.prototype.hasOwnProperty.call(value, key);\n}\n\nfunction optionalNonEmptyString(\n\tvalue: unknown,\n\tfield: string,\n): string | undefined {\n\tif (value === undefined || value === null) {\n\t\treturn undefined;\n\t}\n\tif (typeof value !== \"string\" || value.trim().length === 0) {\n\t\tthrow new MaestroAppServerPolicyControlError(-32602, `Invalid ${field}`);\n\t}\n\treturn value.trim();\n}\n\nfunction parseUser(value: unknown): ActionApprovalContext[\"user\"] | undefined {\n\tif (value === undefined || value === null) {\n\t\treturn undefined;\n\t}\n\tif (!isRecord(value)) {\n\t\tthrow new MaestroAppServerPolicyControlError(-32602, \"Invalid user\");\n\t}\n\tconst id = optionalNonEmptyString(value.id, \"user.id\");\n\tconst orgId = optionalNonEmptyString(value.orgId, \"user.orgId\");\n\tif (!id || !orgId) {\n\t\tthrow new MaestroAppServerPolicyControlError(-32602, \"Invalid user\");\n\t}\n\treturn { id, orgId };\n}\n\nfunction parseSession(\n\tvalue: unknown,\n\trequireId: boolean,\n): ActionApprovalContext[\"session\"] {\n\tif (value === undefined || value === null) {\n\t\treturn undefined;\n\t}\n\tif (!isRecord(value)) {\n\t\tthrow new MaestroAppServerPolicyControlError(-32602, \"Invalid session\");\n\t}\n\tconst id = optionalNonEmptyString(value.id, \"session.id\");\n\tif (requireId && !id) {\n\t\tthrow new MaestroAppServerPolicyControlError(-32602, \"Invalid session.id\");\n\t}\n\tif (value.startedAt === undefined || value.startedAt === null) {\n\t\tthrow new MaestroAppServerPolicyControlError(\n\t\t\t-32602,\n\t\t\t\"Invalid session.startedAt\",\n\t\t);\n\t}\n\tconst startedAt =\n\t\tvalue.startedAt instanceof Date\n\t\t\t? new Date(value.startedAt.getTime())\n\t\t\t: new Date(\n\t\t\t\t\toptionalNonEmptyString(value.startedAt, \"session.startedAt\") ?? \"\",\n\t\t\t\t);\n\tif (!Number.isFinite(startedAt.getTime())) {\n\t\tthrow new MaestroAppServerPolicyControlError(\n\t\t\t-32602,\n\t\t\t\"Invalid session.startedAt\",\n\t\t);\n\t}\n\treturn { id: id ?? \"app-server-policy-check\", startedAt };\n}\n\nfunction parseActionContext(\n\tvalue: unknown,\n\tfallbackSession?: ActionApprovalContext[\"session\"],\n): ActionApprovalContext | undefined {\n\tif (value === undefined || value === null) {\n\t\treturn undefined;\n\t}\n\tif (!isRecord(value)) {\n\t\tthrow new MaestroAppServerPolicyControlError(-32602, \"Invalid action\");\n\t}\n\tconst toolName = optionalNonEmptyString(value.toolName, \"action.toolName\");\n\tif (!toolName) {\n\t\tthrow new MaestroAppServerPolicyControlError(\n\t\t\t-32602,\n\t\t\t\"Invalid action.toolName\",\n\t\t);\n\t}\n\tconst actionSession =\n\t\tvalue.session === undefined || value.session === null\n\t\t\t? fallbackSession\n\t\t\t: parseSession(value.session, false);\n\treturn {\n\t\ttoolName,\n\t\targs: hasOwnKey(value, \"args\") ? value.args : {},\n\t\tmetadata: isRecord(value.metadata)\n\t\t\t? (value.metadata as ActionApprovalContext[\"metadata\"])\n\t\t\t: undefined,\n\t\tuser: parseUser(value.user),\n\t\tsession: actionSession,\n\t\tuserIntent: optionalNonEmptyString(value.userIntent, \"action.userIntent\"),\n\t};\n}\n\nfunction parseUsage(\n\tvalue: unknown,\n): { tokenCount?: number; activeSessionCount?: number } | undefined {\n\tif (value === undefined || value === null) {\n\t\treturn undefined;\n\t}\n\tif (!isRecord(value)) {\n\t\tthrow new MaestroAppServerPolicyControlError(-32602, \"Invalid usage\");\n\t}\n\tconst usage: { tokenCount?: number; activeSessionCount?: number } = {};\n\tfor (const key of [\"tokenCount\", \"activeSessionCount\"] as const) {\n\t\tif (value[key] === undefined || value[key] === null) {\n\t\t\tcontinue;\n\t\t}\n\t\tif (\n\t\t\ttypeof value[key] !== \"number\" ||\n\t\t\t!Number.isFinite(value[key]) ||\n\t\t\tvalue[key] < 0\n\t\t) {\n\t\t\tthrow new MaestroAppServerPolicyControlError(\n\t\t\t\t-32602,\n\t\t\t\t`Invalid usage.${key}`,\n\t\t\t);\n\t\t}\n\t\tusage[key] = value[key];\n\t}\n\treturn usage;\n}\n\nfunction firstReason(\n\tchecks: MaestroAppServerPolicyCheckItem[],\n): string | undefined {\n\treturn checks.find((check) => !check.allowed)?.reason;\n}\n\nexport function createMaestroAppServerPolicyControl(): MaestroAppServerPolicyControl {\n\treturn {\n\t\treadPolicy() {\n\t\t\tconst policy = readCurrentPolicy();\n\t\t\treturn {\n\t\t\t\tloaded: policy !== null,\n\t\t\t\tpolicy: clonePolicySnapshot(policy),\n\t\t\t};\n\t\t},\n\n\t\tasync checkPolicy(params = {}) {\n\t\t\tif (!isRecord(params)) {\n\t\t\t\tthrow new MaestroAppServerPolicyControlError(-32602, \"Invalid params\");\n\t\t\t}\n\t\t\tconst checks: MaestroAppServerPolicyCheckItem[] = [];\n\t\t\tconst session = parseSession(params.session, false);\n\t\t\tconst action = parseActionContext(params.action, session);\n\t\t\tconst sessionForLimits = action?.session ?? session;\n\t\t\tif (action) {\n\t\t\t\tconst result = await checkPolicy(action);\n\t\t\t\tchecks.push({\n\t\t\t\t\tkind: \"action\",\n\t\t\t\t\tallowed: result.allowed,\n\t\t\t\t\t...(result.reason ? { reason: result.reason } : {}),\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst modelId = optionalNonEmptyString(params.modelId, \"modelId\");\n\t\t\tif (modelId) {\n\t\t\t\tconst result = checkModelPolicy(modelId);\n\t\t\t\tchecks.push({\n\t\t\t\t\tkind: \"model\",\n\t\t\t\t\tallowed: result.allowed,\n\t\t\t\t\t...(result.reason ? { reason: result.reason } : {}),\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tif (sessionForLimits) {\n\t\t\t\tconst result = checkSessionLimits(\n\t\t\t\t\tsessionForLimits,\n\t\t\t\t\tparseUsage(params.usage),\n\t\t\t\t);\n\t\t\t\tchecks.push({\n\t\t\t\t\tkind: \"session\",\n\t\t\t\t\tallowed: result.allowed,\n\t\t\t\t\t...(result.reason ? { reason: result.reason } : {}),\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tif (checks.length === 0) {\n\t\t\t\tthrow new MaestroAppServerPolicyControlError(\n\t\t\t\t\t-32602,\n\t\t\t\t\t\"Missing policy check target\",\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst reason = firstReason(checks);\n\t\t\treturn {\n\t\t\t\tallowed: checks.every((check) => check.allowed),\n\t\t\t\t...(reason ? { reason } : {}),\n\t\t\t\tchecks,\n\t\t\t};\n\t\t},\n\n\t\tlistRequirements() {\n\t\t\tconst policy = readCurrentPolicy();\n\t\t\tconst requiredSkills = deepFreezeSnapshot([\n\t\t\t\t...(policy?.skills?.required ?? []),\n\t\t\t]);\n\t\t\treturn {\n\t\t\t\trequirements: requiredSkills.map((id) => ({\n\t\t\t\t\tkind: \"skill\",\n\t\t\t\t\tid,\n\t\t\t\t\trequired: true,\n\t\t\t\t})),\n\t\t\t\trequiredSkills,\n\t\t\t};\n\t\t},\n\t};\n}\n"]}
@@ -0,0 +1,22 @@
1
+ import { type MaestroAppServerClientMethod, type MaestroAppServerProtocolModeId, type MaestroAppServerProtocolModeListResult, type MaestroAppServerProtocolModeSetResult } from "@evalops/contracts";
2
+ type UnknownRecord = Record<string, unknown>;
3
+ export declare class MaestroAppServerProtocolModesError extends Error {
4
+ readonly code: number;
5
+ constructor(code: number, message: string);
6
+ }
7
+ export interface MaestroAppServerProtocolModeDecision {
8
+ allowed: boolean;
9
+ reason?: string;
10
+ }
11
+ export interface MaestroAppServerProtocolModes {
12
+ listModes(params?: UnknownRecord): MaestroAppServerProtocolModeListResult;
13
+ setMode(params?: UnknownRecord): MaestroAppServerProtocolModeSetResult;
14
+ checkMethod(method: MaestroAppServerClientMethod): MaestroAppServerProtocolModeDecision;
15
+ activeMode(): MaestroAppServerProtocolModeId;
16
+ }
17
+ export interface MaestroAppServerProtocolModesOptions {
18
+ initialMode?: MaestroAppServerProtocolModeId;
19
+ }
20
+ export declare function createMaestroAppServerProtocolModes(options?: MaestroAppServerProtocolModesOptions): MaestroAppServerProtocolModes;
21
+ export {};
22
+ //# sourceMappingURL=protocol-modes-api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol-modes-api.d.ts","sourceRoot":"","sources":["../../src/app-server/protocol-modes-api.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,4BAA4B,EAEjC,KAAK,8BAA8B,EACnC,KAAK,sCAAsC,EAC3C,KAAK,qCAAqC,EAI1C,MAAM,oBAAoB,CAAC;AAE5B,KAAK,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AA+B7C,qBAAa,kCAAmC,SAAQ,KAAK;IAE3D,QAAQ,CAAC,IAAI,EAAE,MAAM;gBAAZ,IAAI,EAAE,MAAM,EACrB,OAAO,EAAE,MAAM;CAKhB;AAED,MAAM,WAAW,oCAAoC;IACpD,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,6BAA6B;IAC7C,SAAS,CAAC,MAAM,CAAC,EAAE,aAAa,GAAG,sCAAsC,CAAC;IAC1E,OAAO,CAAC,MAAM,CAAC,EAAE,aAAa,GAAG,qCAAqC,CAAC;IACvE,WAAW,CACV,MAAM,EAAE,4BAA4B,GAClC,oCAAoC,CAAC;IACxC,UAAU,IAAI,8BAA8B,CAAC;CAC7C;AAED,MAAM,WAAW,oCAAoC;IACpD,WAAW,CAAC,EAAE,8BAA8B,CAAC;CAC7C;AA2ED,wBAAgB,mCAAmC,CAClD,OAAO,GAAE,oCAAyC,GAChD,6BAA6B,CAsC/B"}
@@ -0,0 +1,124 @@
1
+ import { maestroAppServerClientMethods, maestroAppServerProtocolModeIds, maestroAppServerServerMethods, } from "@evalops/contracts";
2
+ const DEFAULT_MODE = "standard";
3
+ const REVIEW_BLOCKED_METHODS = new Set([
4
+ "network/fetch",
5
+ "sandbox/proof/run",
6
+ "externalAgent/import",
7
+ "pluginBundle/install",
8
+ "pluginBundle/remove",
9
+ "remoteControl/lease/heartbeat",
10
+ "remoteControl/drain",
11
+ "command/exec",
12
+ "command/exec/write",
13
+ "command/exec/terminate",
14
+ "fs/writeFile",
15
+ "fs/createDirectory",
16
+ "fs/remove",
17
+ "fs/copy",
18
+ "fs/watch",
19
+ "thread/metadata/update",
20
+ "thread/name/set",
21
+ "thread/goal/set",
22
+ "thread/goal/clear",
23
+ "thread/start",
24
+ "thread/fork",
25
+ "thread/archive",
26
+ "thread/unarchive",
27
+ "thread/delete",
28
+ ]);
29
+ export class MaestroAppServerProtocolModesError extends Error {
30
+ constructor(code, message) {
31
+ super(message);
32
+ this.code = code;
33
+ this.name = "MaestroAppServerProtocolModesError";
34
+ }
35
+ }
36
+ function normalizeMode(value) {
37
+ if (value === undefined || value === null) {
38
+ throw new MaestroAppServerProtocolModesError(-32602, "Missing mode");
39
+ }
40
+ if (typeof value !== "string") {
41
+ throw new MaestroAppServerProtocolModesError(-32602, "Invalid mode");
42
+ }
43
+ if (maestroAppServerProtocolModeIds.includes(value)) {
44
+ return value;
45
+ }
46
+ throw new MaestroAppServerProtocolModesError(-32602, "Invalid mode");
47
+ }
48
+ function isRecord(value) {
49
+ return typeof value === "object" && value !== null && !Array.isArray(value);
50
+ }
51
+ function paramsRecord(params) {
52
+ if (params === undefined) {
53
+ return {};
54
+ }
55
+ if (isRecord(params)) {
56
+ return params;
57
+ }
58
+ throw new MaestroAppServerProtocolModesError(-32602, "Invalid params");
59
+ }
60
+ function modeLabel(mode) {
61
+ switch (mode) {
62
+ case "review":
63
+ return "Review";
64
+ case "realtime":
65
+ return "Realtime";
66
+ case "standard":
67
+ return "Standard";
68
+ }
69
+ }
70
+ function isMethodAllowedInMode(mode, method) {
71
+ if (mode !== "review") {
72
+ return true;
73
+ }
74
+ return !REVIEW_BLOCKED_METHODS.has(method);
75
+ }
76
+ function describeMode(mode) {
77
+ const allowedMethods = maestroAppServerClientMethods.filter((method) => isMethodAllowedInMode(mode, method));
78
+ const blockedMethods = maestroAppServerClientMethods.filter((method) => !isMethodAllowedInMode(mode, method));
79
+ return {
80
+ id: mode,
81
+ label: modeLabel(mode),
82
+ readOnly: mode === "review",
83
+ realtime: mode === "realtime",
84
+ allowedMethods: [...allowedMethods],
85
+ blockedMethods: [...blockedMethods],
86
+ serverNotifications: mode === "realtime" ? [...maestroAppServerServerMethods] : [],
87
+ };
88
+ }
89
+ export function createMaestroAppServerProtocolModes(options = {}) {
90
+ let activeMode = options.initialMode === undefined
91
+ ? DEFAULT_MODE
92
+ : normalizeMode(options.initialMode);
93
+ return {
94
+ listModes(params) {
95
+ paramsRecord(params);
96
+ return {
97
+ activeMode,
98
+ defaultMode: DEFAULT_MODE,
99
+ modes: maestroAppServerProtocolModeIds.map(describeMode),
100
+ };
101
+ },
102
+ setMode(params) {
103
+ const normalizedParams = paramsRecord(params);
104
+ activeMode = normalizeMode(normalizedParams.mode);
105
+ return {
106
+ activeMode,
107
+ mode: describeMode(activeMode),
108
+ };
109
+ },
110
+ checkMethod(method) {
111
+ if (isMethodAllowedInMode(activeMode, method)) {
112
+ return { allowed: true };
113
+ }
114
+ return {
115
+ allowed: false,
116
+ reason: `${method} is blocked while protocol mode is ${activeMode}`,
117
+ };
118
+ },
119
+ activeMode() {
120
+ return activeMode;
121
+ },
122
+ };
123
+ }
124
+ //# sourceMappingURL=protocol-modes-api.js.map