@dexto/core 1.1.11 → 1.2.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 (416) hide show
  1. package/README.md +24 -4
  2. package/dist/Dexto.cjs +4 -14
  3. package/dist/Dexto.d.ts +8 -29
  4. package/dist/Dexto.d.ts.map +1 -1
  5. package/dist/Dexto.js +4 -12
  6. package/dist/agent/DextoAgent.cjs +92 -3
  7. package/dist/agent/DextoAgent.d.ts +12 -4
  8. package/dist/agent/DextoAgent.d.ts.map +1 -1
  9. package/dist/agent/DextoAgent.js +52 -3
  10. package/dist/agent/agentCard.js +1 -0
  11. package/dist/agent/error-codes.cjs +1 -0
  12. package/dist/agent/error-codes.d.ts +1 -0
  13. package/dist/agent/error-codes.d.ts.map +1 -1
  14. package/dist/agent/error-codes.js +2 -0
  15. package/dist/agent/errors.cjs +13 -0
  16. package/dist/agent/errors.d.ts +4 -0
  17. package/dist/agent/errors.d.ts.map +1 -1
  18. package/dist/agent/errors.js +14 -0
  19. package/dist/agent/index.js +1 -0
  20. package/dist/agent/registry/error-codes.js +1 -0
  21. package/dist/agent/registry/errors.js +1 -0
  22. package/dist/agent/registry/registry.js +1 -0
  23. package/dist/agent/registry/types.js +1 -0
  24. package/dist/agent/registry/user-registry.js +1 -0
  25. package/dist/agent/schemas.cjs +6 -1
  26. package/dist/agent/schemas.d.ts +113 -3
  27. package/dist/agent/schemas.d.ts.map +1 -1
  28. package/dist/agent/schemas.js +7 -1
  29. package/dist/agent/state-manager.js +1 -0
  30. package/dist/approval/error-codes.js +1 -0
  31. package/dist/approval/errors.js +1 -0
  32. package/dist/approval/index.js +1 -0
  33. package/dist/approval/manager.cjs +30 -0
  34. package/dist/approval/manager.d.ts +23 -1
  35. package/dist/approval/manager.d.ts.map +1 -1
  36. package/dist/approval/manager.js +31 -0
  37. package/dist/approval/providers/event-based-approval-provider.js +1 -0
  38. package/dist/approval/providers/factory.js +1 -0
  39. package/dist/approval/providers/noop-approval-provider.js +1 -0
  40. package/dist/approval/schemas.cjs +36 -0
  41. package/dist/approval/schemas.d.ts +173 -0
  42. package/dist/approval/schemas.d.ts.map +1 -1
  43. package/dist/approval/schemas.js +33 -0
  44. package/dist/approval/types.cjs +1 -0
  45. package/dist/approval/types.d.ts +27 -1
  46. package/dist/approval/types.d.ts.map +1 -1
  47. package/dist/approval/types.js +2 -0
  48. package/dist/chunk-C6A6W6XS.js +53 -0
  49. package/dist/config/agent-resolver.js +1 -0
  50. package/dist/config/error-codes.js +1 -0
  51. package/dist/config/errors.js +1 -0
  52. package/dist/config/loader.js +1 -0
  53. package/dist/config/writer.js +1 -0
  54. package/dist/context/compression/middle-removal.js +1 -0
  55. package/dist/context/compression/oldest-removal.js +1 -0
  56. package/dist/context/error-codes.js +1 -0
  57. package/dist/context/errors.js +1 -0
  58. package/dist/context/index.js +1 -0
  59. package/dist/context/manager.cjs +36 -1
  60. package/dist/context/manager.d.ts.map +1 -1
  61. package/dist/context/manager.js +27 -1
  62. package/dist/context/media-helpers.js +1 -0
  63. package/dist/context/utils.cjs +102 -6
  64. package/dist/context/utils.d.ts +35 -2
  65. package/dist/context/utils.d.ts.map +1 -1
  66. package/dist/context/utils.js +100 -6
  67. package/dist/errors/DextoBaseError.js +1 -0
  68. package/dist/errors/DextoRuntimeError.js +1 -0
  69. package/dist/errors/DextoValidationError.js +1 -0
  70. package/dist/errors/index.js +1 -0
  71. package/dist/errors/result-bridge.js +1 -0
  72. package/dist/errors/types.cjs +3 -0
  73. package/dist/errors/types.d.ts +7 -2
  74. package/dist/errors/types.d.ts.map +1 -1
  75. package/dist/errors/types.js +4 -0
  76. package/dist/events/index.cjs +1 -0
  77. package/dist/events/index.d.ts +6 -2
  78. package/dist/events/index.d.ts.map +1 -1
  79. package/dist/events/index.js +2 -0
  80. package/dist/filesystem/error-codes.cjs +53 -0
  81. package/dist/filesystem/error-codes.d.ts +31 -0
  82. package/dist/filesystem/error-codes.d.ts.map +1 -0
  83. package/dist/filesystem/error-codes.js +30 -0
  84. package/dist/filesystem/errors.cjs +303 -0
  85. package/dist/filesystem/errors.d.ts +109 -0
  86. package/dist/filesystem/errors.d.ts.map +1 -0
  87. package/dist/filesystem/errors.js +280 -0
  88. package/dist/filesystem/filesystem-service.cjs +482 -0
  89. package/dist/filesystem/filesystem-service.d.ts +57 -0
  90. package/dist/filesystem/filesystem-service.d.ts.map +1 -0
  91. package/dist/filesystem/filesystem-service.js +449 -0
  92. package/dist/filesystem/index.cjs +37 -0
  93. package/dist/filesystem/index.d.ts +11 -0
  94. package/dist/filesystem/index.d.ts.map +1 -0
  95. package/dist/filesystem/index.js +11 -0
  96. package/dist/filesystem/path-validator.cjs +172 -0
  97. package/dist/filesystem/path-validator.d.ts +53 -0
  98. package/dist/filesystem/path-validator.d.ts.map +1 -0
  99. package/dist/filesystem/path-validator.js +139 -0
  100. package/dist/filesystem/types.cjs +16 -0
  101. package/dist/filesystem/types.d.ts +171 -0
  102. package/dist/filesystem/types.d.ts.map +1 -0
  103. package/dist/filesystem/types.js +0 -0
  104. package/dist/index.browser.js +1 -0
  105. package/dist/index.cjs +3 -3
  106. package/dist/index.d.ts +2 -1
  107. package/dist/index.d.ts.map +1 -1
  108. package/dist/index.js +3 -2
  109. package/dist/llm/error-codes.js +1 -0
  110. package/dist/llm/errors.js +1 -0
  111. package/dist/llm/formatters/anthropic.js +1 -0
  112. package/dist/llm/formatters/factory.js +1 -0
  113. package/dist/llm/formatters/openai.js +1 -0
  114. package/dist/llm/formatters/vercel.js +1 -0
  115. package/dist/llm/registry.cjs +15 -15
  116. package/dist/llm/registry.d.ts +1 -1
  117. package/dist/llm/registry.js +16 -15
  118. package/dist/llm/resolver.js +1 -0
  119. package/dist/llm/schemas.cjs +6 -2
  120. package/dist/llm/schemas.d.ts +10 -0
  121. package/dist/llm/schemas.d.ts.map +1 -1
  122. package/dist/llm/schemas.js +7 -2
  123. package/dist/llm/services/anthropic.cjs +67 -0
  124. package/dist/llm/services/anthropic.d.ts +6 -0
  125. package/dist/llm/services/anthropic.d.ts.map +1 -1
  126. package/dist/llm/services/anthropic.js +27 -0
  127. package/dist/llm/services/factory.js +1 -0
  128. package/dist/llm/services/openai.cjs +87 -0
  129. package/dist/llm/services/openai.d.ts +6 -0
  130. package/dist/llm/services/openai.d.ts.map +1 -1
  131. package/dist/llm/services/openai.js +47 -0
  132. package/dist/llm/services/test-utils.integration.cjs +1 -1
  133. package/dist/llm/services/test-utils.integration.js +2 -1
  134. package/dist/llm/services/vercel.cjs +144 -97
  135. package/dist/llm/services/vercel.d.ts +6 -1
  136. package/dist/llm/services/vercel.d.ts.map +1 -1
  137. package/dist/llm/services/vercel.js +105 -98
  138. package/dist/llm/tokenizer/anthropic.js +1 -0
  139. package/dist/llm/tokenizer/default.js +1 -0
  140. package/dist/llm/tokenizer/factory.js +1 -0
  141. package/dist/llm/tokenizer/google.js +1 -0
  142. package/dist/llm/tokenizer/openai.cjs +1 -1
  143. package/dist/llm/tokenizer/openai.d.ts +1 -1
  144. package/dist/llm/tokenizer/openai.js +2 -1
  145. package/dist/llm/tokenizer/types.js +1 -0
  146. package/dist/llm/types.d.ts +2 -2
  147. package/dist/llm/types.d.ts.map +1 -1
  148. package/dist/llm/types.js +1 -0
  149. package/dist/llm/validation.js +1 -0
  150. package/dist/logger/browser.js +1 -0
  151. package/dist/logger/logger.d.ts +42 -0
  152. package/dist/logger/logger.d.ts.map +1 -1
  153. package/dist/logger/logger.js +1 -0
  154. package/dist/mcp/error-codes.cjs +1 -0
  155. package/dist/mcp/error-codes.d.ts +1 -0
  156. package/dist/mcp/error-codes.d.ts.map +1 -1
  157. package/dist/mcp/error-codes.js +2 -0
  158. package/dist/mcp/errors.cjs +12 -0
  159. package/dist/mcp/errors.d.ts +7 -0
  160. package/dist/mcp/errors.d.ts.map +1 -1
  161. package/dist/mcp/errors.js +13 -0
  162. package/dist/mcp/manager.cjs +66 -16
  163. package/dist/mcp/manager.d.ts +7 -0
  164. package/dist/mcp/manager.d.ts.map +1 -1
  165. package/dist/mcp/manager.js +67 -16
  166. package/dist/mcp/mcp-client.js +1 -0
  167. package/dist/mcp/resolver.js +1 -0
  168. package/dist/mcp/schemas.js +1 -0
  169. package/dist/mcp/types.d.ts +1 -1
  170. package/dist/mcp/types.d.ts.map +1 -1
  171. package/dist/memory/error-codes.js +1 -0
  172. package/dist/memory/errors.js +1 -0
  173. package/dist/memory/index.js +1 -0
  174. package/dist/memory/manager.js +1 -0
  175. package/dist/memory/schemas.js +1 -0
  176. package/dist/plugins/builtins/content-policy.js +1 -0
  177. package/dist/plugins/builtins/response-sanitizer.js +1 -0
  178. package/dist/plugins/error-codes.js +1 -0
  179. package/dist/plugins/index.js +1 -0
  180. package/dist/plugins/loader.js +1 -0
  181. package/dist/plugins/manager.js +1 -0
  182. package/dist/plugins/registrations/builtins.js +1 -0
  183. package/dist/plugins/schemas.js +1 -0
  184. package/dist/preferences/constants.js +1 -0
  185. package/dist/preferences/error-codes.js +1 -0
  186. package/dist/preferences/errors.js +1 -0
  187. package/dist/preferences/index.js +1 -0
  188. package/dist/preferences/loader.cjs +3 -1
  189. package/dist/preferences/loader.d.ts +10 -1
  190. package/dist/preferences/loader.d.ts.map +1 -1
  191. package/dist/preferences/loader.js +4 -1
  192. package/dist/preferences/schemas.cjs +2 -1
  193. package/dist/preferences/schemas.d.ts +8 -0
  194. package/dist/preferences/schemas.d.ts.map +1 -1
  195. package/dist/preferences/schemas.js +3 -1
  196. package/dist/process/command-validator.cjs +544 -0
  197. package/dist/process/command-validator.d.ts +46 -0
  198. package/dist/process/command-validator.d.ts.map +1 -0
  199. package/dist/process/command-validator.js +521 -0
  200. package/dist/process/error-codes.cjs +47 -0
  201. package/dist/process/error-codes.d.ts +25 -0
  202. package/dist/process/error-codes.d.ts.map +1 -0
  203. package/dist/process/error-codes.js +24 -0
  204. package/dist/process/errors.cjs +244 -0
  205. package/dist/process/errors.d.ts +87 -0
  206. package/dist/process/errors.d.ts.map +1 -0
  207. package/dist/process/errors.js +221 -0
  208. package/dist/process/index.cjs +37 -0
  209. package/dist/process/index.d.ts +11 -0
  210. package/dist/process/index.d.ts.map +1 -0
  211. package/dist/process/index.js +11 -0
  212. package/dist/process/process-service.cjs +443 -0
  213. package/dist/process/process-service.d.ts +62 -0
  214. package/dist/process/process-service.d.ts.map +1 -0
  215. package/dist/process/process-service.js +410 -0
  216. package/dist/process/types.cjs +16 -0
  217. package/dist/process/types.d.ts +107 -0
  218. package/dist/process/types.d.ts.map +1 -0
  219. package/dist/process/types.js +0 -0
  220. package/dist/prompts/error-codes.js +1 -0
  221. package/dist/prompts/errors.js +1 -0
  222. package/dist/prompts/index.js +1 -0
  223. package/dist/prompts/name-validation.js +1 -0
  224. package/dist/prompts/prompt-manager.js +1 -0
  225. package/dist/prompts/providers/custom-prompt-provider.js +1 -0
  226. package/dist/prompts/providers/file-prompt-provider.js +1 -0
  227. package/dist/prompts/providers/mcp-prompt-provider.js +1 -0
  228. package/dist/prompts/providers/starter-prompt-provider.js +1 -0
  229. package/dist/prompts/schemas.js +1 -0
  230. package/dist/prompts/utils.js +1 -0
  231. package/dist/resources/error-codes.js +1 -0
  232. package/dist/resources/errors.js +1 -0
  233. package/dist/resources/handlers/blob-handler.js +1 -0
  234. package/dist/resources/handlers/factory.js +1 -0
  235. package/dist/resources/handlers/filesystem-handler.cjs +1 -1
  236. package/dist/resources/handlers/filesystem-handler.d.ts.map +1 -1
  237. package/dist/resources/handlers/filesystem-handler.js +2 -1
  238. package/dist/resources/index.js +1 -0
  239. package/dist/resources/internal-provider.js +1 -0
  240. package/dist/resources/manager.js +1 -0
  241. package/dist/resources/reference-parser.js +1 -0
  242. package/dist/resources/schemas.js +1 -0
  243. package/dist/search/index.js +1 -0
  244. package/dist/search/search-service.js +1 -0
  245. package/dist/session/chat-session.cjs +2 -2
  246. package/dist/session/chat-session.d.ts +2 -2
  247. package/dist/session/chat-session.js +3 -2
  248. package/dist/session/error-codes.js +1 -0
  249. package/dist/session/errors.js +1 -0
  250. package/dist/session/history/database.js +1 -0
  251. package/dist/session/history/factory.js +1 -0
  252. package/dist/session/history/memory.js +1 -0
  253. package/dist/session/index.js +1 -0
  254. package/dist/session/schemas.js +1 -0
  255. package/dist/session/session-manager.d.ts +6 -0
  256. package/dist/session/session-manager.d.ts.map +1 -1
  257. package/dist/session/session-manager.js +1 -0
  258. package/dist/session/title-generator.js +1 -0
  259. package/dist/storage/blob/factory.cjs +3 -3
  260. package/dist/storage/blob/factory.d.ts +3 -1
  261. package/dist/storage/blob/factory.d.ts.map +1 -1
  262. package/dist/storage/blob/factory.js +4 -3
  263. package/dist/storage/blob/local-blob-store.cjs +18 -2
  264. package/dist/storage/blob/local-blob-store.d.ts +2 -1
  265. package/dist/storage/blob/local-blob-store.d.ts.map +1 -1
  266. package/dist/storage/blob/local-blob-store.js +19 -2
  267. package/dist/storage/blob/schemas.js +1 -0
  268. package/dist/storage/cache/factory.js +1 -0
  269. package/dist/storage/cache/memory-cache-store.js +1 -0
  270. package/dist/storage/cache/redis-store.js +1 -0
  271. package/dist/storage/cache/schemas.js +1 -0
  272. package/dist/storage/database/factory.cjs +7 -5
  273. package/dist/storage/database/factory.d.ts +3 -1
  274. package/dist/storage/database/factory.d.ts.map +1 -1
  275. package/dist/storage/database/factory.js +8 -5
  276. package/dist/storage/database/memory-database-store.js +1 -0
  277. package/dist/storage/database/postgres-store.js +1 -0
  278. package/dist/storage/database/schemas.cjs +1 -1
  279. package/dist/storage/database/schemas.js +2 -1
  280. package/dist/storage/database/sqlite-store.cjs +20 -2
  281. package/dist/storage/database/sqlite-store.d.ts +2 -1
  282. package/dist/storage/database/sqlite-store.d.ts.map +1 -1
  283. package/dist/storage/database/sqlite-store.js +21 -2
  284. package/dist/storage/error-codes.cjs +1 -0
  285. package/dist/storage/error-codes.d.ts +1 -0
  286. package/dist/storage/error-codes.d.ts.map +1 -1
  287. package/dist/storage/error-codes.js +2 -0
  288. package/dist/storage/errors.cjs +15 -0
  289. package/dist/storage/errors.d.ts +4 -0
  290. package/dist/storage/errors.d.ts.map +1 -1
  291. package/dist/storage/errors.js +16 -0
  292. package/dist/storage/index.js +1 -0
  293. package/dist/storage/schemas.js +1 -0
  294. package/dist/storage/storage-manager.cjs +7 -5
  295. package/dist/storage/storage-manager.d.ts +5 -2
  296. package/dist/storage/storage-manager.d.ts.map +1 -1
  297. package/dist/storage/storage-manager.js +8 -5
  298. package/dist/systemPrompt/contributors.js +1 -0
  299. package/dist/systemPrompt/error-codes.js +1 -0
  300. package/dist/systemPrompt/errors.js +1 -0
  301. package/dist/systemPrompt/in-built-prompts.js +1 -0
  302. package/dist/systemPrompt/index.js +1 -0
  303. package/dist/systemPrompt/manager.js +1 -0
  304. package/dist/systemPrompt/registry.js +1 -0
  305. package/dist/systemPrompt/schemas.js +1 -0
  306. package/dist/telemetry/decorators.cjs +175 -0
  307. package/dist/telemetry/decorators.d.ts +17 -0
  308. package/dist/telemetry/decorators.d.ts.map +1 -0
  309. package/dist/telemetry/decorators.js +157 -0
  310. package/dist/telemetry/exporters.cjs +108 -0
  311. package/dist/telemetry/exporters.d.ts +29 -0
  312. package/dist/telemetry/exporters.d.ts.map +1 -0
  313. package/dist/telemetry/exporters.js +85 -0
  314. package/dist/telemetry/index.cjs +28 -0
  315. package/dist/telemetry/index.d.ts +2 -0
  316. package/dist/telemetry/index.d.ts.map +1 -0
  317. package/dist/telemetry/index.js +5 -0
  318. package/dist/telemetry/schemas.cjs +71 -0
  319. package/dist/telemetry/schemas.d.ts +54 -0
  320. package/dist/telemetry/schemas.d.ts.map +1 -0
  321. package/dist/telemetry/schemas.js +48 -0
  322. package/dist/telemetry/telemetry.cjs +228 -0
  323. package/dist/telemetry/telemetry.d.ts +74 -0
  324. package/dist/telemetry/telemetry.d.ts.map +1 -0
  325. package/dist/telemetry/telemetry.js +205 -0
  326. package/dist/telemetry/types.cjs +16 -0
  327. package/dist/telemetry/types.d.ts +22 -0
  328. package/dist/telemetry/types.d.ts.map +1 -0
  329. package/dist/telemetry/types.js +0 -0
  330. package/dist/telemetry/utils.cjs +87 -0
  331. package/dist/telemetry/utils.d.ts +21 -0
  332. package/dist/telemetry/utils.d.ts.map +1 -0
  333. package/dist/telemetry/utils.js +62 -0
  334. package/dist/tools/confirmation/allowed-tools-provider/factory.js +1 -0
  335. package/dist/tools/confirmation/allowed-tools-provider/in-memory.js +1 -0
  336. package/dist/tools/confirmation/allowed-tools-provider/storage.js +1 -0
  337. package/dist/tools/error-codes.js +1 -0
  338. package/dist/tools/errors.js +1 -0
  339. package/dist/tools/index.js +1 -0
  340. package/dist/tools/internal-tools/constants.cjs +39 -0
  341. package/dist/tools/internal-tools/constants.d.ts +12 -0
  342. package/dist/tools/internal-tools/constants.d.ts.map +1 -0
  343. package/dist/tools/internal-tools/constants.js +16 -0
  344. package/dist/tools/internal-tools/implementations/ask-user-tool.js +1 -0
  345. package/dist/tools/internal-tools/implementations/bash-exec-tool.cjs +106 -0
  346. package/dist/tools/internal-tools/implementations/bash-exec-tool.d.ts +13 -0
  347. package/dist/tools/internal-tools/implementations/bash-exec-tool.d.ts.map +1 -0
  348. package/dist/tools/internal-tools/implementations/bash-exec-tool.js +73 -0
  349. package/dist/tools/internal-tools/implementations/bash-output-tool.cjs +49 -0
  350. package/dist/tools/internal-tools/implementations/bash-output-tool.d.ts +12 -0
  351. package/dist/tools/internal-tools/implementations/bash-output-tool.d.ts.map +1 -0
  352. package/dist/tools/internal-tools/implementations/bash-output-tool.js +26 -0
  353. package/dist/tools/internal-tools/implementations/edit-file-tool.cjs +62 -0
  354. package/dist/tools/internal-tools/implementations/edit-file-tool.d.ts +12 -0
  355. package/dist/tools/internal-tools/implementations/edit-file-tool.d.ts.map +1 -0
  356. package/dist/tools/internal-tools/implementations/edit-file-tool.js +39 -0
  357. package/dist/tools/internal-tools/implementations/glob-files-tool.cjs +57 -0
  358. package/dist/tools/internal-tools/implementations/glob-files-tool.d.ts +12 -0
  359. package/dist/tools/internal-tools/implementations/glob-files-tool.d.ts.map +1 -0
  360. package/dist/tools/internal-tools/implementations/glob-files-tool.js +34 -0
  361. package/dist/tools/internal-tools/implementations/grep-content-tool.cjs +71 -0
  362. package/dist/tools/internal-tools/implementations/grep-content-tool.d.ts +12 -0
  363. package/dist/tools/internal-tools/implementations/grep-content-tool.d.ts.map +1 -0
  364. package/dist/tools/internal-tools/implementations/grep-content-tool.js +48 -0
  365. package/dist/tools/internal-tools/implementations/kill-process-tool.cjs +47 -0
  366. package/dist/tools/internal-tools/implementations/kill-process-tool.d.ts +12 -0
  367. package/dist/tools/internal-tools/implementations/kill-process-tool.d.ts.map +1 -0
  368. package/dist/tools/internal-tools/implementations/kill-process-tool.js +24 -0
  369. package/dist/tools/internal-tools/implementations/read-file-tool.cjs +55 -0
  370. package/dist/tools/internal-tools/implementations/read-file-tool.d.ts +12 -0
  371. package/dist/tools/internal-tools/implementations/read-file-tool.d.ts.map +1 -0
  372. package/dist/tools/internal-tools/implementations/read-file-tool.js +32 -0
  373. package/dist/tools/internal-tools/implementations/search-history-tool.js +1 -0
  374. package/dist/tools/internal-tools/implementations/write-file-tool.cjs +56 -0
  375. package/dist/tools/internal-tools/implementations/write-file-tool.d.ts +12 -0
  376. package/dist/tools/internal-tools/implementations/write-file-tool.d.ts.map +1 -0
  377. package/dist/tools/internal-tools/implementations/write-file-tool.js +33 -0
  378. package/dist/tools/internal-tools/index.cjs +3 -1
  379. package/dist/tools/internal-tools/index.d.ts +1 -0
  380. package/dist/tools/internal-tools/index.d.ts.map +1 -1
  381. package/dist/tools/internal-tools/index.js +1 -0
  382. package/dist/tools/internal-tools/provider.js +1 -0
  383. package/dist/tools/internal-tools/registry.cjs +40 -4
  384. package/dist/tools/internal-tools/registry.d.ts +5 -9
  385. package/dist/tools/internal-tools/registry.d.ts.map +1 -1
  386. package/dist/tools/internal-tools/registry.js +41 -3
  387. package/dist/tools/schemas.cjs +18 -5
  388. package/dist/tools/schemas.d.ts +30 -1
  389. package/dist/tools/schemas.d.ts.map +1 -1
  390. package/dist/tools/schemas.js +15 -2
  391. package/dist/tools/tool-manager.cjs +158 -19
  392. package/dist/tools/tool-manager.d.ts +48 -2
  393. package/dist/tools/tool-manager.d.ts.map +1 -1
  394. package/dist/tools/tool-manager.js +118 -19
  395. package/dist/utils/api-key-resolver.js +1 -0
  396. package/dist/utils/api-key-store.js +1 -0
  397. package/dist/utils/async-context.js +1 -0
  398. package/dist/utils/debug.js +1 -0
  399. package/dist/utils/env.js +1 -0
  400. package/dist/utils/error-conversion.js +1 -0
  401. package/dist/utils/execution-context.js +1 -0
  402. package/dist/utils/fs-walk.js +1 -0
  403. package/dist/utils/path.js +1 -0
  404. package/dist/utils/port-utils.js +1 -0
  405. package/dist/utils/redactor.js +1 -0
  406. package/dist/utils/result.js +1 -0
  407. package/dist/utils/safe-stringify.js +1 -0
  408. package/dist/utils/schema-metadata.js +1 -0
  409. package/dist/utils/schema.js +1 -0
  410. package/dist/utils/service-initializer.cjs +42 -4
  411. package/dist/utils/service-initializer.d.ts +2 -1
  412. package/dist/utils/service-initializer.d.ts.map +1 -1
  413. package/dist/utils/service-initializer.js +33 -4
  414. package/dist/utils/user-info.js +1 -0
  415. package/dist/utils/zod-schema-converter.js +1 -0
  416. package/package.json +11 -1
@@ -0,0 +1,443 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var process_service_exports = {};
30
+ __export(process_service_exports, {
31
+ ProcessService: () => ProcessService
32
+ });
33
+ module.exports = __toCommonJS(process_service_exports);
34
+ var import_node_child_process = require("node:child_process");
35
+ var crypto = __toESM(require("node:crypto"), 1);
36
+ var path = __toESM(require("node:path"), 1);
37
+ var import_command_validator = require("./command-validator.js");
38
+ var import_errors = require("./errors.js");
39
+ var import_logger = require("../logger/index.js");
40
+ const DEFAULT_TIMEOUT = 12e4;
41
+ const DEFAULT_MAX_TIMEOUT = 6e5;
42
+ const DEFAULT_MAX_CONCURRENT_PROCESSES = 5;
43
+ const DEFAULT_MAX_OUTPUT_BUFFER = 1024 * 1024;
44
+ class ProcessService {
45
+ config;
46
+ commandValidator;
47
+ initialized = false;
48
+ backgroundProcesses = /* @__PURE__ */ new Map();
49
+ constructor(config = {}) {
50
+ this.config = {
51
+ securityLevel: config.securityLevel || "moderate",
52
+ maxTimeout: config.maxTimeout || DEFAULT_MAX_TIMEOUT,
53
+ maxConcurrentProcesses: config.maxConcurrentProcesses || DEFAULT_MAX_CONCURRENT_PROCESSES,
54
+ maxOutputBuffer: config.maxOutputBuffer || DEFAULT_MAX_OUTPUT_BUFFER,
55
+ allowedCommands: config.allowedCommands || [],
56
+ blockedCommands: config.blockedCommands || [],
57
+ environment: config.environment || {},
58
+ workingDirectory: config.workingDirectory
59
+ };
60
+ this.commandValidator = new import_command_validator.CommandValidator(this.config);
61
+ }
62
+ /**
63
+ * Initialize the service
64
+ */
65
+ async initialize() {
66
+ if (this.initialized) {
67
+ import_logger.logger.debug("ProcessService already initialized");
68
+ return;
69
+ }
70
+ this.backgroundProcesses.clear();
71
+ this.initialized = true;
72
+ import_logger.logger.info("ProcessService initialized successfully");
73
+ }
74
+ /**
75
+ * Execute a command
76
+ */
77
+ async executeCommand(command, options = {}) {
78
+ if (!this.initialized) {
79
+ throw import_errors.ProcessError.notInitialized();
80
+ }
81
+ const validation = this.commandValidator.validateCommand(command);
82
+ if (!validation.isValid || !validation.normalizedCommand) {
83
+ throw import_errors.ProcessError.invalidCommand(command, validation.error || "Unknown error");
84
+ }
85
+ const normalizedCommand = validation.normalizedCommand;
86
+ if (validation.requiresApproval) {
87
+ if (!options.approvalFunction) {
88
+ throw import_errors.ProcessError.approvalRequired(
89
+ normalizedCommand,
90
+ "Command requires approval but no approval mechanism provided"
91
+ );
92
+ }
93
+ import_logger.logger.info(
94
+ `Command requires approval: ${normalizedCommand} - requesting user confirmation`
95
+ );
96
+ const approved = await options.approvalFunction(normalizedCommand);
97
+ if (!approved) {
98
+ import_logger.logger.info(`Command approval denied: ${normalizedCommand}`);
99
+ throw import_errors.ProcessError.approvalDenied(normalizedCommand);
100
+ }
101
+ import_logger.logger.info(`Command approved: ${normalizedCommand}`);
102
+ }
103
+ const rawTimeout = options.timeout !== void 0 && Number.isFinite(options.timeout) ? options.timeout : DEFAULT_TIMEOUT;
104
+ const timeout = Math.max(1, Math.min(rawTimeout, this.config.maxTimeout));
105
+ const cwd = this.resolveSafeCwd(options.cwd);
106
+ const env = {};
107
+ for (const [key, value] of Object.entries({
108
+ ...process.env,
109
+ ...this.config.environment,
110
+ ...options.env
111
+ })) {
112
+ if (value !== void 0) {
113
+ env[key] = value;
114
+ }
115
+ }
116
+ if (options.runInBackground) {
117
+ return await this.executeInBackground(normalizedCommand, options);
118
+ }
119
+ return await this.executeForeground(normalizedCommand, {
120
+ cwd,
121
+ timeout,
122
+ env,
123
+ ...options.description !== void 0 && { description: options.description }
124
+ });
125
+ }
126
+ /**
127
+ * Execute command in foreground with timeout
128
+ */
129
+ executeForeground(command, options) {
130
+ return new Promise((resolve, reject) => {
131
+ const startTime = Date.now();
132
+ let stdout = "";
133
+ let stderr = "";
134
+ let killed = false;
135
+ let closed = false;
136
+ import_logger.logger.debug(`Executing command: ${command}`);
137
+ const child = (0, import_node_child_process.spawn)(command, {
138
+ cwd: options.cwd,
139
+ env: options.env,
140
+ shell: true
141
+ });
142
+ const timeoutHandle = setTimeout(() => {
143
+ killed = true;
144
+ child.kill("SIGTERM");
145
+ setTimeout(() => {
146
+ if (!closed && child.exitCode === null) {
147
+ child.kill("SIGKILL");
148
+ }
149
+ }, 5e3);
150
+ }, options.timeout);
151
+ child.stdout?.on("data", (data) => {
152
+ stdout += data.toString();
153
+ });
154
+ child.stderr?.on("data", (data) => {
155
+ stderr += data.toString();
156
+ });
157
+ child.on("close", (code, signal) => {
158
+ closed = true;
159
+ clearTimeout(timeoutHandle);
160
+ const duration = Date.now() - startTime;
161
+ if (killed) {
162
+ reject(import_errors.ProcessError.timeout(command, options.timeout));
163
+ return;
164
+ }
165
+ let exitCode = typeof code === "number" ? code : 1;
166
+ if (code === null) {
167
+ stderr += `
168
+ Process terminated by signal ${signal ?? "UNKNOWN"}`;
169
+ }
170
+ import_logger.logger.debug(
171
+ `Command completed with exit code ${exitCode} in ${duration}ms: ${command}`
172
+ );
173
+ resolve({
174
+ stdout,
175
+ stderr,
176
+ exitCode,
177
+ duration
178
+ });
179
+ });
180
+ child.on("error", (error) => {
181
+ clearTimeout(timeoutHandle);
182
+ if (error.code === "ENOENT") {
183
+ reject(import_errors.ProcessError.commandNotFound(command));
184
+ } else if (error.code === "EACCES") {
185
+ reject(import_errors.ProcessError.permissionDenied(command));
186
+ } else {
187
+ reject(import_errors.ProcessError.executionFailed(command, error.message));
188
+ }
189
+ });
190
+ });
191
+ }
192
+ /**
193
+ * Execute command in background
194
+ */
195
+ async executeInBackground(command, options) {
196
+ const runningCount = Array.from(this.backgroundProcesses.values()).filter(
197
+ (p) => p.status === "running"
198
+ ).length;
199
+ if (runningCount >= this.config.maxConcurrentProcesses) {
200
+ throw import_errors.ProcessError.tooManyProcesses(runningCount, this.config.maxConcurrentProcesses);
201
+ }
202
+ const processId = crypto.randomBytes(4).toString("hex");
203
+ const cwd = this.resolveSafeCwd(options.cwd);
204
+ const env = {};
205
+ for (const [key, value] of Object.entries({
206
+ ...process.env,
207
+ ...this.config.environment,
208
+ ...options.env
209
+ })) {
210
+ if (value !== void 0) {
211
+ env[key] = value;
212
+ }
213
+ }
214
+ import_logger.logger.debug(`Starting background process ${processId}: ${command}`);
215
+ const child = (0, import_node_child_process.spawn)(command, {
216
+ cwd,
217
+ env,
218
+ shell: true,
219
+ detached: false
220
+ });
221
+ const outputBuffer = {
222
+ stdout: [],
223
+ stderr: [],
224
+ complete: false,
225
+ lastRead: Date.now(),
226
+ bytesUsed: 0,
227
+ truncated: false
228
+ };
229
+ const bgProcess = {
230
+ processId,
231
+ command,
232
+ child,
233
+ startedAt: /* @__PURE__ */ new Date(),
234
+ status: "running",
235
+ outputBuffer,
236
+ description: options.description
237
+ };
238
+ this.backgroundProcesses.set(processId, bgProcess);
239
+ const bgTimeout = Math.max(
240
+ 1,
241
+ Math.min(options.timeout || DEFAULT_TIMEOUT, this.config.maxTimeout)
242
+ );
243
+ const killTimer = setTimeout(() => {
244
+ if (bgProcess.status === "running") {
245
+ import_logger.logger.warn(
246
+ `Background process ${processId} timed out after ${bgTimeout}ms, sending SIGTERM`
247
+ );
248
+ child.kill("SIGTERM");
249
+ setTimeout(() => {
250
+ if (bgProcess.status === "running") {
251
+ import_logger.logger.warn(
252
+ `Background process ${processId} did not respond to SIGTERM, sending SIGKILL`
253
+ );
254
+ child.kill("SIGKILL");
255
+ }
256
+ }, 5e3);
257
+ }
258
+ }, bgTimeout);
259
+ child.stdout?.on("data", (data) => {
260
+ const chunk = data.toString();
261
+ const chunkBytes = Buffer.byteLength(chunk, "utf8");
262
+ if (outputBuffer.bytesUsed + chunkBytes <= this.config.maxOutputBuffer) {
263
+ outputBuffer.stdout.push(chunk);
264
+ outputBuffer.bytesUsed += chunkBytes;
265
+ } else {
266
+ if (!outputBuffer.truncated) {
267
+ outputBuffer.truncated = true;
268
+ import_logger.logger.warn(`Output buffer full for process ${processId}`);
269
+ }
270
+ }
271
+ });
272
+ child.stderr?.on("data", (data) => {
273
+ const chunk = data.toString();
274
+ const chunkBytes = Buffer.byteLength(chunk, "utf8");
275
+ if (outputBuffer.bytesUsed + chunkBytes <= this.config.maxOutputBuffer) {
276
+ outputBuffer.stderr.push(chunk);
277
+ outputBuffer.bytesUsed += chunkBytes;
278
+ } else {
279
+ if (!outputBuffer.truncated) {
280
+ outputBuffer.truncated = true;
281
+ import_logger.logger.warn(`Error buffer full for process ${processId}`);
282
+ }
283
+ }
284
+ });
285
+ child.on("close", (code) => {
286
+ clearTimeout(killTimer);
287
+ bgProcess.status = code === 0 ? "completed" : "failed";
288
+ bgProcess.exitCode = code ?? void 0;
289
+ bgProcess.completedAt = /* @__PURE__ */ new Date();
290
+ bgProcess.outputBuffer.complete = true;
291
+ import_logger.logger.debug(`Background process ${processId} completed with exit code ${code}`);
292
+ });
293
+ child.on("error", (error) => {
294
+ clearTimeout(killTimer);
295
+ bgProcess.status = "failed";
296
+ bgProcess.completedAt = /* @__PURE__ */ new Date();
297
+ bgProcess.outputBuffer.complete = true;
298
+ const chunk = `Error: ${error.message}`;
299
+ const chunkBytes = Buffer.byteLength(chunk, "utf8");
300
+ if (bgProcess.outputBuffer.bytesUsed + chunkBytes <= this.config.maxOutputBuffer) {
301
+ bgProcess.outputBuffer.stderr.push(chunk);
302
+ bgProcess.outputBuffer.bytesUsed += chunkBytes;
303
+ } else {
304
+ if (!bgProcess.outputBuffer.truncated) {
305
+ bgProcess.outputBuffer.truncated = true;
306
+ import_logger.logger.warn(`Error buffer full for process ${processId}`);
307
+ }
308
+ }
309
+ import_logger.logger.error(`Background process ${processId} failed: ${error.message}`);
310
+ });
311
+ return {
312
+ processId,
313
+ command,
314
+ pid: child.pid,
315
+ startedAt: bgProcess.startedAt,
316
+ description: options.description
317
+ };
318
+ }
319
+ /**
320
+ * Get output from a background process
321
+ */
322
+ async getProcessOutput(processId) {
323
+ if (!this.initialized) {
324
+ throw import_errors.ProcessError.notInitialized();
325
+ }
326
+ const bgProcess = this.backgroundProcesses.get(processId);
327
+ if (!bgProcess) {
328
+ throw import_errors.ProcessError.processNotFound(processId);
329
+ }
330
+ const stdout = bgProcess.outputBuffer.stdout.join("");
331
+ const stderr = bgProcess.outputBuffer.stderr.join("");
332
+ bgProcess.outputBuffer.stdout = [];
333
+ bgProcess.outputBuffer.stderr = [];
334
+ bgProcess.outputBuffer.lastRead = Date.now();
335
+ bgProcess.outputBuffer.bytesUsed = 0;
336
+ return {
337
+ stdout,
338
+ stderr,
339
+ status: bgProcess.status,
340
+ exitCode: bgProcess.exitCode,
341
+ duration: bgProcess.completedAt ? bgProcess.completedAt.getTime() - bgProcess.startedAt.getTime() : void 0
342
+ };
343
+ }
344
+ /**
345
+ * Kill a background process
346
+ */
347
+ async killProcess(processId) {
348
+ if (!this.initialized) {
349
+ throw import_errors.ProcessError.notInitialized();
350
+ }
351
+ const bgProcess = this.backgroundProcesses.get(processId);
352
+ if (!bgProcess) {
353
+ throw import_errors.ProcessError.processNotFound(processId);
354
+ }
355
+ if (bgProcess.status !== "running") {
356
+ import_logger.logger.debug(`Process ${processId} is not running (status: ${bgProcess.status})`);
357
+ return;
358
+ }
359
+ try {
360
+ bgProcess.child.kill("SIGTERM");
361
+ setTimeout(() => {
362
+ if (bgProcess.child.exitCode === null) {
363
+ bgProcess.child.kill("SIGKILL");
364
+ }
365
+ }, 5e3);
366
+ import_logger.logger.debug(`Process ${processId} sent SIGTERM`);
367
+ } catch (error) {
368
+ throw import_errors.ProcessError.killFailed(
369
+ processId,
370
+ error instanceof Error ? error.message : String(error)
371
+ );
372
+ }
373
+ }
374
+ /**
375
+ * List all background processes
376
+ */
377
+ async listProcesses() {
378
+ if (!this.initialized) {
379
+ throw import_errors.ProcessError.notInitialized();
380
+ }
381
+ return Array.from(this.backgroundProcesses.values()).map((bgProcess) => ({
382
+ processId: bgProcess.processId,
383
+ command: bgProcess.command,
384
+ pid: bgProcess.child.pid,
385
+ status: bgProcess.status,
386
+ startedAt: bgProcess.startedAt,
387
+ completedAt: bgProcess.completedAt,
388
+ exitCode: bgProcess.exitCode,
389
+ description: bgProcess.description
390
+ }));
391
+ }
392
+ /**
393
+ * Get buffer size in bytes
394
+ */
395
+ getBufferSize(buffer) {
396
+ const stdoutSize = buffer.stdout.reduce((sum, line) => sum + line.length, 0);
397
+ const stderrSize = buffer.stderr.reduce((sum, line) => sum + line.length, 0);
398
+ return stdoutSize + stderrSize;
399
+ }
400
+ /**
401
+ * Get service configuration
402
+ */
403
+ getConfig() {
404
+ return { ...this.config };
405
+ }
406
+ /**
407
+ * Resolve and confine cwd to the configured working directory
408
+ */
409
+ resolveSafeCwd(cwd) {
410
+ const baseDir = this.config.workingDirectory || process.cwd();
411
+ if (!cwd) return baseDir;
412
+ const candidate = path.isAbsolute(cwd) ? path.resolve(cwd) : path.resolve(baseDir, cwd);
413
+ const rel = path.relative(baseDir, candidate);
414
+ const outside = rel.startsWith("..") || path.isAbsolute(rel);
415
+ if (outside) {
416
+ throw import_errors.ProcessError.invalidWorkingDirectory(
417
+ cwd,
418
+ `Working directory must be within ${baseDir}`
419
+ );
420
+ }
421
+ return candidate;
422
+ }
423
+ /**
424
+ * Cleanup completed processes
425
+ */
426
+ async cleanup() {
427
+ const now = Date.now();
428
+ const CLEANUP_AGE = 36e5;
429
+ for (const [processId, bgProcess] of this.backgroundProcesses.entries()) {
430
+ if (bgProcess.status !== "running" && bgProcess.completedAt) {
431
+ const age = now - bgProcess.completedAt.getTime();
432
+ if (age > CLEANUP_AGE) {
433
+ this.backgroundProcesses.delete(processId);
434
+ import_logger.logger.debug(`Cleaned up old process ${processId}`);
435
+ }
436
+ }
437
+ }
438
+ }
439
+ }
440
+ // Annotate the CommonJS export names for ESM import in node:
441
+ 0 && (module.exports = {
442
+ ProcessService
443
+ });
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Process Service
3
+ *
4
+ * Secure command execution and process management for Dexto internal tools
5
+ */
6
+ import { ProcessConfig, ExecuteOptions, ProcessResult, ProcessHandle, ProcessOutput, ProcessInfo } from './types.js';
7
+ /**
8
+ * ProcessService - Handles command execution and process management
9
+ * TODO: Add tests for this class
10
+ */
11
+ export declare class ProcessService {
12
+ private config;
13
+ private commandValidator;
14
+ private initialized;
15
+ private backgroundProcesses;
16
+ constructor(config?: Partial<ProcessConfig>);
17
+ /**
18
+ * Initialize the service
19
+ */
20
+ initialize(): Promise<void>;
21
+ /**
22
+ * Execute a command
23
+ */
24
+ executeCommand(command: string, options?: ExecuteOptions): Promise<ProcessResult | ProcessHandle>;
25
+ /**
26
+ * Execute command in foreground with timeout
27
+ */
28
+ private executeForeground;
29
+ /**
30
+ * Execute command in background
31
+ */
32
+ private executeInBackground;
33
+ /**
34
+ * Get output from a background process
35
+ */
36
+ getProcessOutput(processId: string): Promise<ProcessOutput>;
37
+ /**
38
+ * Kill a background process
39
+ */
40
+ killProcess(processId: string): Promise<void>;
41
+ /**
42
+ * List all background processes
43
+ */
44
+ listProcesses(): Promise<ProcessInfo[]>;
45
+ /**
46
+ * Get buffer size in bytes
47
+ */
48
+ private getBufferSize;
49
+ /**
50
+ * Get service configuration
51
+ */
52
+ getConfig(): Readonly<ProcessConfig>;
53
+ /**
54
+ * Resolve and confine cwd to the configured working directory
55
+ */
56
+ private resolveSafeCwd;
57
+ /**
58
+ * Cleanup completed processes
59
+ */
60
+ cleanup(): Promise<void>;
61
+ }
62
+ //# sourceMappingURL=process-service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"process-service.d.ts","sourceRoot":"","sources":["../../src/process/process-service.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH,OAAO,EACH,aAAa,EACb,cAAc,EACd,aAAa,EACb,aAAa,EACb,aAAa,EACb,WAAW,EAEd,MAAM,YAAY,CAAC;AAyBpB;;;GAGG;AACH,qBAAa,cAAc;IACvB,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,gBAAgB,CAAmB;IAC3C,OAAO,CAAC,WAAW,CAAkB;IACrC,OAAO,CAAC,mBAAmB,CAA6C;gBAE5D,MAAM,GAAE,OAAO,CAAC,aAAa,CAAM;IAiB/C;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAajC;;OAEG;IACG,cAAc,CAChB,OAAO,EAAE,MAAM,EACf,OAAO,GAAE,cAAmB,GAC7B,OAAO,CAAC,aAAa,GAAG,aAAa,CAAC;IAwEzC;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAsFzB;;OAEG;YACW,mBAAmB;IAiKjC;;OAEG;IACG,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IA+BjE;;OAEG;IACG,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAmCnD;;OAEG;IACG,aAAa,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;IAiB7C;;OAEG;IACH,OAAO,CAAC,aAAa;IAMrB;;OAEG;IACH,SAAS,IAAI,QAAQ,CAAC,aAAa,CAAC;IAIpC;;OAEG;IACH,OAAO,CAAC,cAAc;IAetB;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAcjC"}