yuzuha 0.1.5 → 0.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 (547) hide show
  1. package/CHANGELOG.md +80 -0
  2. package/README.md +171 -115
  3. package/VERSIONING.md +119 -7
  4. package/assets/canvas/Inter-Bold.ttf +0 -0
  5. package/assets/canvas/Inter-Regular.ttf +0 -0
  6. package/assets/canvas/OFL.txt +92 -0
  7. package/assets/canvas/ORIGIN.md +8 -0
  8. package/benchmarks/compare.mjs +8 -2
  9. package/benchmarks/parser.mjs +66 -0
  10. package/benchmarks/performance.mjs +87 -0
  11. package/benchmarks/rate-limits.mjs +138 -0
  12. package/benchmarks/refinement.mjs +99 -0
  13. package/benchmarks/results/rate-limits-comparison.json +273 -0
  14. package/benchmarks/results/v0.1.6/performance-0.1.5.json +205 -0
  15. package/benchmarks/results/v0.1.6/performance-0.1.6.json +263 -0
  16. package/benchmarks/results/v0.1.6/refinement-audio.json +147 -0
  17. package/benchmarks/results/v0.1.6/refinement-final-repeat.json +147 -0
  18. package/benchmarks/results/v0.1.6/refinement-final.json +147 -0
  19. package/benchmarks/results/v0.1.6/refinement-initial.json +117 -0
  20. package/benchmarks/results/v0.1.6/runtime-0.1.5.json +341 -0
  21. package/benchmarks/results/v0.1.6/runtime-0.1.6-refined.json +406 -0
  22. package/benchmarks/results/v0.1.6/runtime-0.1.6-repeat.json +406 -0
  23. package/benchmarks/results/v0.1.6/runtime-0.1.6.json +406 -0
  24. package/benchmarks/results/v0.1.7/parser-comparison.json +170 -0
  25. package/bridges/lavalink/README.md +101 -0
  26. package/bridges/lavalink/application.yml +20 -0
  27. package/bridges/lavalink/build.mjs +38 -0
  28. package/bridges/lavalink/integration.mjs +161 -0
  29. package/bridges/lavalink/results/node22.json +39 -0
  30. package/bridges/lavalink/results/node26.json +39 -0
  31. package/bridges/lavalink/src/AudioController.java +149 -0
  32. package/bridges/lavalink/src/WebmOpus.java +82 -0
  33. package/dist/canvas.d.ts +10 -0
  34. package/dist/canvas.d.ts.map +1 -0
  35. package/dist/canvas.js +11 -0
  36. package/dist/canvas.js.map +1 -0
  37. package/dist/cli/arguments.d.ts +6 -0
  38. package/dist/cli/arguments.d.ts.map +1 -1
  39. package/dist/cli/arguments.js +39 -9
  40. package/dist/cli/arguments.js.map +1 -1
  41. package/dist/cli/bot-template-catalog.d.ts +33 -0
  42. package/dist/cli/bot-template-catalog.d.ts.map +1 -0
  43. package/dist/cli/bot-template-catalog.js +20 -0
  44. package/dist/cli/bot-template-catalog.js.map +1 -0
  45. package/dist/cli/bot-template-commands.d.ts +2 -0
  46. package/dist/cli/bot-template-commands.d.ts.map +1 -0
  47. package/dist/cli/bot-template-commands.js +358 -0
  48. package/dist/cli/bot-template-commands.js.map +1 -0
  49. package/dist/cli/bot-template-content.d.ts +13 -0
  50. package/dist/cli/bot-template-content.d.ts.map +1 -0
  51. package/dist/cli/bot-template-content.js +69 -0
  52. package/dist/cli/bot-template-content.js.map +1 -0
  53. package/dist/cli/bot-template-feature-tests.d.ts +2 -0
  54. package/dist/cli/bot-template-feature-tests.d.ts.map +1 -0
  55. package/dist/cli/bot-template-feature-tests.js +165 -0
  56. package/dist/cli/bot-template-feature-tests.js.map +1 -0
  57. package/dist/cli/bot-template-tests.d.ts +3 -0
  58. package/dist/cli/bot-template-tests.d.ts.map +1 -0
  59. package/dist/cli/bot-template-tests.js +67 -0
  60. package/dist/cli/bot-template-tests.js.map +1 -0
  61. package/dist/cli/bot-templates.d.ts +3 -0
  62. package/dist/cli/bot-templates.d.ts.map +1 -0
  63. package/dist/cli/bot-templates.js +154 -0
  64. package/dist/cli/bot-templates.js.map +1 -0
  65. package/dist/cli/main.d.ts.map +1 -1
  66. package/dist/cli/main.js +13 -3
  67. package/dist/cli/main.js.map +1 -1
  68. package/dist/cli/scaffold.d.ts +3 -1
  69. package/dist/cli/scaffold.d.ts.map +1 -1
  70. package/dist/cli/scaffold.js +26 -8
  71. package/dist/cli/scaffold.js.map +1 -1
  72. package/dist/cli/version.d.ts +1 -3
  73. package/dist/cli/version.d.ts.map +1 -1
  74. package/dist/cli/version.js +1 -6
  75. package/dist/cli/version.js.map +1 -1
  76. package/dist/cli.js +1 -1
  77. package/dist/cli.js.map +1 -1
  78. package/dist/commands/arguments.d.ts.map +1 -1
  79. package/dist/commands/arguments.js +56 -45
  80. package/dist/commands/arguments.js.map +1 -1
  81. package/dist/commands/context.d.ts +44 -10
  82. package/dist/commands/context.d.ts.map +1 -1
  83. package/dist/commands/context.js +80 -27
  84. package/dist/commands/context.js.map +1 -1
  85. package/dist/contracts.d.ts +1 -1
  86. package/dist/contracts.d.ts.map +1 -1
  87. package/dist/contracts.js.map +1 -1
  88. package/dist/domain/canvas.d.ts +240 -0
  89. package/dist/domain/canvas.d.ts.map +1 -0
  90. package/dist/domain/canvas.js +226 -0
  91. package/dist/domain/canvas.js.map +1 -0
  92. package/dist/domain/decimal.d.ts +4 -0
  93. package/dist/domain/decimal.d.ts.map +1 -0
  94. package/dist/domain/decimal.js +84 -0
  95. package/dist/domain/decimal.js.map +1 -0
  96. package/dist/domain/embeds.d.ts +36 -0
  97. package/dist/domain/embeds.d.ts.map +1 -0
  98. package/dist/domain/embeds.js +259 -0
  99. package/dist/domain/embeds.js.map +1 -0
  100. package/dist/domain/message-query.d.ts +39 -0
  101. package/dist/domain/message-query.d.ts.map +1 -0
  102. package/dist/domain/message-query.js +108 -0
  103. package/dist/domain/message-query.js.map +1 -0
  104. package/dist/domain/messages.d.ts +89 -13
  105. package/dist/domain/messages.d.ts.map +1 -1
  106. package/dist/domain/messages.js.map +1 -1
  107. package/dist/domain/music-state.d.ts +3 -0
  108. package/dist/domain/music-state.d.ts.map +1 -0
  109. package/dist/domain/music-state.js +10 -0
  110. package/dist/domain/music-state.js.map +1 -0
  111. package/dist/domain/music.d.ts +199 -0
  112. package/dist/domain/music.d.ts.map +1 -0
  113. package/dist/domain/music.js +2 -0
  114. package/dist/domain/music.js.map +1 -0
  115. package/dist/domain/state-validation.d.ts.map +1 -1
  116. package/dist/domain/state-validation.js +2 -0
  117. package/dist/domain/state-validation.js.map +1 -1
  118. package/dist/domain/state.d.ts +1 -0
  119. package/dist/domain/state.d.ts.map +1 -1
  120. package/dist/domain/state.js.map +1 -1
  121. package/dist/domain/track-queue.d.ts +24 -0
  122. package/dist/domain/track-queue.d.ts.map +1 -0
  123. package/dist/domain/track-queue.js +103 -0
  124. package/dist/domain/track-queue.js.map +1 -0
  125. package/dist/domain/variable-query.d.ts +29 -0
  126. package/dist/domain/variable-query.d.ts.map +1 -0
  127. package/dist/domain/variable-query.js +53 -0
  128. package/dist/domain/variable-query.js.map +1 -0
  129. package/dist/framework/bot.d.ts +17 -2
  130. package/dist/framework/bot.d.ts.map +1 -1
  131. package/dist/framework/bot.js +167 -39
  132. package/dist/framework/bot.js.map +1 -1
  133. package/dist/framework/command-registry.d.ts.map +1 -1
  134. package/dist/framework/command-registry.js +8 -1
  135. package/dist/framework/command-registry.js.map +1 -1
  136. package/dist/framework/events.d.ts +12 -0
  137. package/dist/framework/events.d.ts.map +1 -1
  138. package/dist/framework/events.js.map +1 -1
  139. package/dist/framework/options.d.ts +6 -0
  140. package/dist/framework/options.d.ts.map +1 -1
  141. package/dist/framework/options.js.map +1 -1
  142. package/dist/framework/rate-limits.d.ts +4 -0
  143. package/dist/framework/rate-limits.d.ts.map +1 -1
  144. package/dist/framework/rate-limits.js +31 -15
  145. package/dist/framework/rate-limits.js.map +1 -1
  146. package/dist/framework/reporting.js +1 -1
  147. package/dist/framework/reporting.js.map +1 -1
  148. package/dist/images.d.ts +3 -0
  149. package/dist/images.d.ts.map +1 -0
  150. package/dist/images.js +2 -0
  151. package/dist/images.js.map +1 -0
  152. package/dist/index.d.ts +8 -3
  153. package/dist/index.d.ts.map +1 -1
  154. package/dist/index.js +2 -0
  155. package/dist/index.js.map +1 -1
  156. package/dist/infrastructure/canvas/render.d.ts +3 -0
  157. package/dist/infrastructure/canvas/render.d.ts.map +1 -0
  158. package/dist/infrastructure/canvas/render.js +118 -0
  159. package/dist/infrastructure/canvas/render.js.map +1 -0
  160. package/dist/infrastructure/canvas/worker.mjs +286 -0
  161. package/dist/infrastructure/fluxer/lavalink-bridge.d.ts +34 -0
  162. package/dist/infrastructure/fluxer/lavalink-bridge.d.ts.map +1 -0
  163. package/dist/infrastructure/fluxer/lavalink-bridge.js +250 -0
  164. package/dist/infrastructure/fluxer/lavalink-bridge.js.map +1 -0
  165. package/dist/infrastructure/fluxer/payload.d.ts +6 -1
  166. package/dist/infrastructure/fluxer/payload.d.ts.map +1 -1
  167. package/dist/infrastructure/fluxer/payload.js +58 -19
  168. package/dist/infrastructure/fluxer/payload.js.map +1 -1
  169. package/dist/infrastructure/fluxer/resources/messages.d.ts.map +1 -1
  170. package/dist/infrastructure/fluxer/resources/messages.js +61 -4
  171. package/dist/infrastructure/fluxer/resources/messages.js.map +1 -1
  172. package/dist/infrastructure/fluxer/resources/threads.d.ts.map +1 -1
  173. package/dist/infrastructure/fluxer/resources/threads.js +9 -0
  174. package/dist/infrastructure/fluxer/resources/threads.js.map +1 -1
  175. package/dist/infrastructure/fluxer/resources/users.d.ts.map +1 -1
  176. package/dist/infrastructure/fluxer/resources/users.js +6 -0
  177. package/dist/infrastructure/fluxer/resources/users.js.map +1 -1
  178. package/dist/infrastructure/fluxer/transport.d.ts.map +1 -1
  179. package/dist/infrastructure/fluxer/transport.js +9 -5
  180. package/dist/infrastructure/fluxer/transport.js.map +1 -1
  181. package/dist/infrastructure/fluxer/voice.d.ts +28 -0
  182. package/dist/infrastructure/fluxer/voice.d.ts.map +1 -0
  183. package/dist/infrastructure/fluxer/voice.js +157 -0
  184. package/dist/infrastructure/fluxer/voice.js.map +1 -0
  185. package/dist/infrastructure/images/transform.d.ts +21 -0
  186. package/dist/infrastructure/images/transform.d.ts.map +1 -0
  187. package/dist/infrastructure/images/transform.js +77 -0
  188. package/dist/infrastructure/images/transform.js.map +1 -0
  189. package/dist/infrastructure/images/worker.mjs +28 -0
  190. package/dist/infrastructure/lavalink/audio-stream.d.ts +12 -0
  191. package/dist/infrastructure/lavalink/audio-stream.d.ts.map +1 -0
  192. package/dist/infrastructure/lavalink/audio-stream.js +95 -0
  193. package/dist/infrastructure/lavalink/audio-stream.js.map +1 -0
  194. package/dist/infrastructure/lavalink/node.d.ts +147 -0
  195. package/dist/infrastructure/lavalink/node.d.ts.map +1 -0
  196. package/dist/infrastructure/lavalink/node.js +498 -0
  197. package/dist/infrastructure/lavalink/node.js.map +1 -0
  198. package/dist/infrastructure/lavalink/protocol.d.ts +10 -0
  199. package/dist/infrastructure/lavalink/protocol.d.ts.map +1 -0
  200. package/dist/infrastructure/lavalink/protocol.js +114 -0
  201. package/dist/infrastructure/lavalink/protocol.js.map +1 -0
  202. package/dist/infrastructure/process-budget.d.ts +3 -0
  203. package/dist/infrastructure/process-budget.d.ts.map +1 -0
  204. package/dist/infrastructure/process-budget.js +17 -0
  205. package/dist/infrastructure/process-budget.js.map +1 -0
  206. package/dist/infrastructure/storage/memory.d.ts +2 -0
  207. package/dist/infrastructure/storage/memory.d.ts.map +1 -1
  208. package/dist/infrastructure/storage/memory.js +8 -0
  209. package/dist/infrastructure/storage/memory.js.map +1 -1
  210. package/dist/infrastructure/storage/sqlite.d.ts +4 -0
  211. package/dist/infrastructure/storage/sqlite.d.ts.map +1 -1
  212. package/dist/infrastructure/storage/sqlite.js +53 -3
  213. package/dist/infrastructure/storage/sqlite.js.map +1 -1
  214. package/dist/music.d.ts +12 -0
  215. package/dist/music.d.ts.map +1 -0
  216. package/dist/music.js +6 -0
  217. package/dist/music.js.map +1 -0
  218. package/dist/ports/canvas.d.ts +5 -0
  219. package/dist/ports/canvas.d.ts.map +1 -0
  220. package/dist/ports/canvas.js +2 -0
  221. package/dist/ports/canvas.js.map +1 -0
  222. package/dist/ports/music.d.ts +25 -0
  223. package/dist/ports/music.d.ts.map +1 -0
  224. package/dist/ports/music.js +2 -0
  225. package/dist/ports/music.js.map +1 -0
  226. package/dist/ports/resources/messages.d.ts +17 -7
  227. package/dist/ports/resources/messages.d.ts.map +1 -1
  228. package/dist/ports/resources/messages.js.map +1 -1
  229. package/dist/ports/resources/threads.d.ts +6 -0
  230. package/dist/ports/resources/threads.d.ts.map +1 -1
  231. package/dist/ports/resources/threads.js.map +1 -1
  232. package/dist/ports/resources/users.d.ts +2 -0
  233. package/dist/ports/resources/users.d.ts.map +1 -1
  234. package/dist/ports/resources/users.js.map +1 -1
  235. package/dist/ports/store.d.ts +5 -1
  236. package/dist/ports/store.d.ts.map +1 -1
  237. package/dist/ports/store.js.map +1 -1
  238. package/dist/ports/voice.d.ts +28 -0
  239. package/dist/ports/voice.d.ts.map +1 -0
  240. package/dist/ports/voice.js +2 -0
  241. package/dist/ports/voice.js.map +1 -0
  242. package/dist/scripting/builtins/canvas.d.ts +2 -0
  243. package/dist/scripting/builtins/canvas.d.ts.map +1 -0
  244. package/dist/scripting/builtins/canvas.js +118 -0
  245. package/dist/scripting/builtins/canvas.js.map +1 -0
  246. package/dist/scripting/builtins/embeds.d.ts +1 -2
  247. package/dist/scripting/builtins/embeds.d.ts.map +1 -1
  248. package/dist/scripting/builtins/embeds.js +90 -35
  249. package/dist/scripting/builtins/embeds.js.map +1 -1
  250. package/dist/scripting/builtins/flow.d.ts.map +1 -1
  251. package/dist/scripting/builtins/flow.js +2 -1
  252. package/dist/scripting/builtins/flow.js.map +1 -1
  253. package/dist/scripting/builtins/http.d.ts.map +1 -1
  254. package/dist/scripting/builtins/http.js +59 -0
  255. package/dist/scripting/builtins/http.js.map +1 -1
  256. package/dist/scripting/builtins/index.d.ts.map +1 -1
  257. package/dist/scripting/builtins/index.js +4 -1
  258. package/dist/scripting/builtins/index.js.map +1 -1
  259. package/dist/scripting/builtins/language/decimals.d.ts +2 -0
  260. package/dist/scripting/builtins/language/decimals.d.ts.map +1 -0
  261. package/dist/scripting/builtins/language/decimals.js +9 -0
  262. package/dist/scripting/builtins/language/decimals.js.map +1 -0
  263. package/dist/scripting/builtins/language/index.d.ts.map +1 -1
  264. package/dist/scripting/builtins/language/index.js +6 -0
  265. package/dist/scripting/builtins/language/index.js.map +1 -1
  266. package/dist/scripting/builtins/language/loops.d.ts.map +1 -1
  267. package/dist/scripting/builtins/language/loops.js +69 -7
  268. package/dist/scripting/builtins/language/loops.js.map +1 -1
  269. package/dist/scripting/builtins/language/objects.d.ts.map +1 -1
  270. package/dist/scripting/builtins/language/objects.js +2 -1
  271. package/dist/scripting/builtins/language/objects.js.map +1 -1
  272. package/dist/scripting/builtins/language/regex.d.ts +2 -0
  273. package/dist/scripting/builtins/language/regex.d.ts.map +1 -0
  274. package/dist/scripting/builtins/language/regex.js +17 -0
  275. package/dist/scripting/builtins/language/regex.js.map +1 -0
  276. package/dist/scripting/builtins/language/sort.d.ts +2 -0
  277. package/dist/scripting/builtins/language/sort.d.ts.map +1 -0
  278. package/dist/scripting/builtins/language/sort.js +55 -0
  279. package/dist/scripting/builtins/language/sort.js.map +1 -0
  280. package/dist/scripting/builtins/language/state.d.ts.map +1 -1
  281. package/dist/scripting/builtins/language/state.js +14 -9
  282. package/dist/scripting/builtins/language/state.js.map +1 -1
  283. package/dist/scripting/builtins/messages.js +3 -3
  284. package/dist/scripting/builtins/messages.js.map +1 -1
  285. package/dist/scripting/builtins/native-expressions.d.ts.map +1 -1
  286. package/dist/scripting/builtins/native-expressions.js +3 -1
  287. package/dist/scripting/builtins/native-expressions.js.map +1 -1
  288. package/dist/scripting/builtins/native-messages.d.ts.map +1 -1
  289. package/dist/scripting/builtins/native-messages.js +17 -0
  290. package/dist/scripting/builtins/native-messages.js.map +1 -1
  291. package/dist/scripting/builtins/native-threads.d.ts.map +1 -1
  292. package/dist/scripting/builtins/native-threads.js +8 -0
  293. package/dist/scripting/builtins/native-threads.js.map +1 -1
  294. package/dist/scripting/builtins/native-users.d.ts.map +1 -1
  295. package/dist/scripting/builtins/native-users.js +5 -0
  296. package/dist/scripting/builtins/native-users.js.map +1 -1
  297. package/dist/scripting/builtins/payload.d.ts +4 -1
  298. package/dist/scripting/builtins/payload.d.ts.map +1 -1
  299. package/dist/scripting/builtins/payload.js +127 -5
  300. package/dist/scripting/builtins/payload.js.map +1 -1
  301. package/dist/scripting/builtins/resource-extras.d.ts.map +1 -1
  302. package/dist/scripting/builtins/resource-extras.js +10 -2
  303. package/dist/scripting/builtins/resource-extras.js.map +1 -1
  304. package/dist/scripting/builtins/schedule.js +8 -8
  305. package/dist/scripting/builtins/schedule.js.map +1 -1
  306. package/dist/scripting/builtins/storage.d.ts.map +1 -1
  307. package/dist/scripting/builtins/storage.js +8 -0
  308. package/dist/scripting/builtins/storage.js.map +1 -1
  309. package/dist/scripting/canvas-execution.d.ts +12 -0
  310. package/dist/scripting/canvas-execution.d.ts.map +1 -0
  311. package/dist/scripting/canvas-execution.js +14 -0
  312. package/dist/scripting/canvas-execution.js.map +1 -0
  313. package/dist/scripting/control-flow.d.ts +8 -0
  314. package/dist/scripting/control-flow.d.ts.map +1 -0
  315. package/dist/scripting/control-flow.js +18 -0
  316. package/dist/scripting/control-flow.js.map +1 -0
  317. package/dist/scripting/evaluator.d.ts +4 -0
  318. package/dist/scripting/evaluator.d.ts.map +1 -1
  319. package/dist/scripting/evaluator.js +81 -36
  320. package/dist/scripting/evaluator.js.map +1 -1
  321. package/dist/scripting/parser.d.ts.map +1 -1
  322. package/dist/scripting/parser.js +20 -11
  323. package/dist/scripting/parser.js.map +1 -1
  324. package/dist/scripting/regex-worker.mjs +69 -0
  325. package/dist/scripting/regex.d.ts +19 -0
  326. package/dist/scripting/regex.d.ts.map +1 -0
  327. package/dist/scripting/regex.js +61 -0
  328. package/dist/scripting/regex.js.map +1 -0
  329. package/dist/scripting/registry.d.ts +2 -1
  330. package/dist/scripting/registry.d.ts.map +1 -1
  331. package/dist/scripting/registry.js +9 -2
  332. package/dist/scripting/registry.js.map +1 -1
  333. package/dist/services/attachments.d.ts +10 -0
  334. package/dist/services/attachments.d.ts.map +1 -0
  335. package/dist/services/attachments.js +54 -0
  336. package/dist/services/attachments.js.map +1 -0
  337. package/dist/services/authorization.d.ts +1 -0
  338. package/dist/services/authorization.d.ts.map +1 -1
  339. package/dist/services/authorization.js +10 -0
  340. package/dist/services/authorization.js.map +1 -1
  341. package/dist/services/canvas.d.ts +43 -0
  342. package/dist/services/canvas.d.ts.map +1 -0
  343. package/dist/services/canvas.js +587 -0
  344. package/dist/services/canvas.js.map +1 -0
  345. package/dist/services/http.d.ts.map +1 -1
  346. package/dist/services/http.js +34 -44
  347. package/dist/services/http.js.map +1 -1
  348. package/dist/services/music-player.d.ts +90 -0
  349. package/dist/services/music-player.d.ts.map +1 -0
  350. package/dist/services/music-player.js +475 -0
  351. package/dist/services/music-player.js.map +1 -0
  352. package/dist/services/music.d.ts +50 -0
  353. package/dist/services/music.d.ts.map +1 -0
  354. package/dist/services/music.js +177 -0
  355. package/dist/services/music.js.map +1 -0
  356. package/dist/services/native-data.d.ts +2 -0
  357. package/dist/services/native-data.d.ts.map +1 -1
  358. package/dist/services/native-data.js +3 -0
  359. package/dist/services/native-data.js.map +1 -1
  360. package/dist/services/resource-authorization.d.ts.map +1 -1
  361. package/dist/services/resource-authorization.js +37 -6
  362. package/dist/services/resource-authorization.js.map +1 -1
  363. package/dist/services/scheduler.d.ts +4 -0
  364. package/dist/services/scheduler.d.ts.map +1 -1
  365. package/dist/services/scheduler.js +10 -2
  366. package/dist/services/scheduler.js.map +1 -1
  367. package/dist/services/variables.d.ts +2 -0
  368. package/dist/services/variables.d.ts.map +1 -1
  369. package/dist/services/variables.js +11 -0
  370. package/dist/services/variables.js.map +1 -1
  371. package/dist/shared/package.d.ts +4 -0
  372. package/dist/shared/package.d.ts.map +1 -0
  373. package/dist/shared/package.js +7 -0
  374. package/dist/shared/package.js.map +1 -0
  375. package/dist/testing/music.d.ts +35 -0
  376. package/dist/testing/music.d.ts.map +1 -0
  377. package/dist/testing/music.js +88 -0
  378. package/dist/testing/music.js.map +1 -0
  379. package/dist/testing.d.ts +2 -0
  380. package/dist/testing.d.ts.map +1 -1
  381. package/dist/testing.js +4 -2
  382. package/dist/testing.js.map +1 -1
  383. package/docs/API.md +60 -3
  384. package/docs/ARCHITECTURE.md +22 -3
  385. package/docs/BENCHMARKS.md +230 -2
  386. package/docs/BOT-BASES.md +168 -0
  387. package/docs/CANVAS.md +274 -0
  388. package/docs/CLI.md +43 -5
  389. package/docs/COOKBOOK.md +1 -1
  390. package/docs/EMBEDS.md +153 -0
  391. package/docs/EVENTS.md +8 -0
  392. package/docs/FUNCTION-GAPS.md +54 -34
  393. package/docs/FUNCTIONS.md +62 -9
  394. package/docs/HTTP.md +41 -0
  395. package/docs/IMAGES.md +109 -0
  396. package/docs/INTEGRATIONS.md +69 -0
  397. package/docs/LANGUAGE-EXTENSIONS.md +106 -0
  398. package/docs/LANGUAGE.md +41 -4
  399. package/docs/MUSIC.md +339 -0
  400. package/docs/NATIVE.md +50 -8
  401. package/docs/PARITY-MATRIX.md +952 -0
  402. package/docs/PARITY.md +50 -26
  403. package/docs/PLAN.md +69 -1
  404. package/docs/PROJECT.md +35 -0
  405. package/docs/QUICKSTART.md +89 -48
  406. package/docs/README.md +44 -24
  407. package/docs/REPOSITORY.md +70 -0
  408. package/docs/SCHEDULER.md +17 -0
  409. package/docs/STORAGE.md +52 -1
  410. package/docs/TESTING.md +21 -1
  411. package/docs/TROUBLESHOOTING.md +11 -1
  412. package/docs/VALIDATION.md +222 -4
  413. package/docs/tutorials/DATA.md +100 -0
  414. package/docs/tutorials/FIRST-COMMAND.md +134 -0
  415. package/docs/tutorials/FUNCTION-MODE.md +100 -0
  416. package/docs/tutorials/TESTING.md +84 -0
  417. package/editors/vscode/functions.json +395 -11
  418. package/editors/vscode/package.json +1 -1
  419. package/examples/canvas/fixtures/avatar.png +0 -0
  420. package/examples/canvas/functions/profile.yuzuha +15 -0
  421. package/examples/canvas/functions/ranking.yuzuha +46 -0
  422. package/examples/canvas/functions/welcome.yuzuha +10 -0
  423. package/examples/canvas/output/function-profile.png +0 -0
  424. package/examples/canvas/output/function-ranking.png +0 -0
  425. package/examples/canvas/output/function-welcome.png +0 -0
  426. package/examples/canvas/output/js-profile.png +0 -0
  427. package/examples/canvas/output/js-ranking.png +0 -0
  428. package/examples/canvas/output/js-welcome.png +0 -0
  429. package/examples/canvas/output/profile.png +0 -0
  430. package/examples/canvas/output/ranking.png +0 -0
  431. package/examples/canvas/output/welcome.png +0 -0
  432. package/examples/canvas/profile.d.mts +3 -0
  433. package/examples/canvas/profile.mjs +20 -0
  434. package/examples/canvas/profile.ts +34 -0
  435. package/examples/canvas/ranking.d.mts +5 -0
  436. package/examples/canvas/ranking.mjs +25 -0
  437. package/examples/canvas/ranking.ts +40 -0
  438. package/examples/canvas/render.ts +48 -0
  439. package/examples/canvas/welcome.d.mts +3 -0
  440. package/examples/canvas/welcome.mjs +14 -0
  441. package/examples/canvas/welcome.ts +27 -0
  442. package/examples/embeds/complete-embed-functions.ts +31 -0
  443. package/examples/embeds/complete-embed.ts +33 -0
  444. package/examples/lavalink.ts +55 -0
  445. package/examples/music-offline.ts +25 -0
  446. package/examples/native-voice.ts +26 -0
  447. package/package.json +49 -5
  448. package/src/canvas.ts +20 -0
  449. package/src/cli/arguments.ts +34 -12
  450. package/src/cli/bot-template-catalog.ts +23 -0
  451. package/src/cli/bot-template-commands.ts +357 -0
  452. package/src/cli/bot-template-content.ts +66 -0
  453. package/src/cli/bot-template-feature-tests.ts +159 -0
  454. package/src/cli/bot-template-tests.ts +68 -0
  455. package/src/cli/bot-templates.ts +155 -0
  456. package/src/cli/main.ts +13 -3
  457. package/src/cli/scaffold.ts +29 -8
  458. package/src/cli/version.ts +1 -10
  459. package/src/cli.ts +1 -1
  460. package/src/commands/arguments.ts +48 -41
  461. package/src/commands/context.ts +83 -26
  462. package/src/contracts.ts +1 -1
  463. package/src/domain/canvas.ts +259 -0
  464. package/src/domain/decimal.ts +75 -0
  465. package/src/domain/embeds.ts +218 -0
  466. package/src/domain/message-query.ts +142 -0
  467. package/src/domain/messages.ts +89 -4
  468. package/src/domain/music-state.ts +10 -0
  469. package/src/domain/music.ts +82 -0
  470. package/src/domain/state-validation.ts +1 -0
  471. package/src/domain/state.ts +1 -0
  472. package/src/domain/track-queue.ts +79 -0
  473. package/src/domain/variable-query.ts +58 -0
  474. package/src/framework/bot.ts +141 -34
  475. package/src/framework/command-registry.ts +7 -1
  476. package/src/framework/events.ts +12 -0
  477. package/src/framework/options.ts +6 -0
  478. package/src/framework/rate-limits.ts +25 -11
  479. package/src/framework/reporting.ts +1 -1
  480. package/src/images.ts +2 -0
  481. package/src/index.ts +9 -3
  482. package/src/infrastructure/canvas/render.ts +100 -0
  483. package/src/infrastructure/canvas/worker.mjs +286 -0
  484. package/src/infrastructure/fluxer/lavalink-bridge.ts +200 -0
  485. package/src/infrastructure/fluxer/payload.ts +54 -13
  486. package/src/infrastructure/fluxer/resources/messages.ts +62 -5
  487. package/src/infrastructure/fluxer/resources/threads.ts +9 -0
  488. package/src/infrastructure/fluxer/resources/users.ts +5 -0
  489. package/src/infrastructure/fluxer/transport.ts +9 -5
  490. package/src/infrastructure/fluxer/voice.ts +108 -0
  491. package/src/infrastructure/images/transform.ts +71 -0
  492. package/src/infrastructure/images/worker.mjs +28 -0
  493. package/src/infrastructure/lavalink/audio-stream.ts +71 -0
  494. package/src/infrastructure/lavalink/node.ts +425 -0
  495. package/src/infrastructure/lavalink/protocol.ts +84 -0
  496. package/src/infrastructure/process-budget.ts +17 -0
  497. package/src/infrastructure/storage/memory.ts +10 -0
  498. package/src/infrastructure/storage/sqlite.ts +52 -4
  499. package/src/music.ts +11 -0
  500. package/src/ports/canvas.ts +5 -0
  501. package/src/ports/music.ts +24 -0
  502. package/src/ports/resources/messages.ts +17 -7
  503. package/src/ports/resources/threads.ts +7 -0
  504. package/src/ports/resources/users.ts +2 -0
  505. package/src/ports/store.ts +5 -1
  506. package/src/ports/voice.ts +26 -0
  507. package/src/scripting/builtins/canvas.ts +117 -0
  508. package/src/scripting/builtins/embeds.ts +87 -28
  509. package/src/scripting/builtins/flow.ts +2 -1
  510. package/src/scripting/builtins/http.ts +44 -0
  511. package/src/scripting/builtins/index.ts +4 -1
  512. package/src/scripting/builtins/language/decimals.ts +10 -0
  513. package/src/scripting/builtins/language/index.ts +6 -0
  514. package/src/scripting/builtins/language/loops.ts +57 -8
  515. package/src/scripting/builtins/language/objects.ts +2 -1
  516. package/src/scripting/builtins/language/regex.ts +19 -0
  517. package/src/scripting/builtins/language/sort.ts +50 -0
  518. package/src/scripting/builtins/language/state.ts +14 -7
  519. package/src/scripting/builtins/messages.ts +3 -3
  520. package/src/scripting/builtins/native-expressions.ts +3 -1
  521. package/src/scripting/builtins/native-messages.ts +17 -0
  522. package/src/scripting/builtins/native-threads.ts +7 -0
  523. package/src/scripting/builtins/native-users.ts +5 -0
  524. package/src/scripting/builtins/payload.ts +121 -6
  525. package/src/scripting/builtins/resource-extras.ts +9 -2
  526. package/src/scripting/builtins/schedule.ts +11 -11
  527. package/src/scripting/builtins/storage.ts +7 -0
  528. package/src/scripting/canvas-execution.ts +23 -0
  529. package/src/scripting/control-flow.ts +13 -0
  530. package/src/scripting/evaluator.ts +52 -18
  531. package/src/scripting/parser.ts +23 -10
  532. package/src/scripting/regex-worker.mjs +69 -0
  533. package/src/scripting/regex.ts +63 -0
  534. package/src/scripting/registry.ts +7 -2
  535. package/src/services/attachments.ts +51 -0
  536. package/src/services/authorization.ts +9 -0
  537. package/src/services/canvas.ts +498 -0
  538. package/src/services/http.ts +26 -33
  539. package/src/services/music-player.ts +340 -0
  540. package/src/services/music.ts +146 -0
  541. package/src/services/native-data.ts +5 -0
  542. package/src/services/resource-authorization.ts +37 -6
  543. package/src/services/scheduler.ts +11 -2
  544. package/src/services/variables.ts +11 -0
  545. package/src/shared/package.ts +10 -0
  546. package/src/testing/music.ts +71 -0
  547. package/src/testing.ts +4 -2
@@ -0,0 +1,92 @@
1
+ Copyright (c) 2016 The Inter Project Authors (https://github.com/rsms/inter)
2
+
3
+ This Font Software is licensed under the SIL Open Font License, Version 1.1.
4
+ This license is copied below, and is also available with a FAQ at:
5
+ http://scripts.sil.org/OFL
6
+
7
+ -----------------------------------------------------------
8
+ SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
9
+ -----------------------------------------------------------
10
+
11
+ PREAMBLE
12
+ The goals of the Open Font License (OFL) are to stimulate worldwide
13
+ development of collaborative font projects, to support the font creation
14
+ efforts of academic and linguistic communities, and to provide a free and
15
+ open framework in which fonts may be shared and improved in partnership
16
+ with others.
17
+
18
+ The OFL allows the licensed fonts to be used, studied, modified and
19
+ redistributed freely as long as they are not sold by themselves. The
20
+ fonts, including any derivative works, can be bundled, embedded,
21
+ redistributed and/or sold with any software provided that any reserved
22
+ names are not used by derivative works. The fonts and derivatives,
23
+ however, cannot be released under any other type of license. The
24
+ requirement for fonts to remain under this license does not apply
25
+ to any document created using the fonts or their derivatives.
26
+
27
+ DEFINITIONS
28
+ "Font Software" refers to the set of files released by the Copyright
29
+ Holder(s) under this license and clearly marked as such. This may
30
+ include source files, build scripts and documentation.
31
+
32
+ "Reserved Font Name" refers to any names specified as such after the
33
+ copyright statement(s).
34
+
35
+ "Original Version" refers to the collection of Font Software components as
36
+ distributed by the Copyright Holder(s).
37
+
38
+ "Modified Version" refers to any derivative made by adding to, deleting,
39
+ or substituting -- in part or in whole -- any of the components of the
40
+ Original Version, by changing formats or by porting the Font Software to a
41
+ new environment.
42
+
43
+ "Author" refers to any designer, engineer, programmer, technical
44
+ writer or other person who contributed to the Font Software.
45
+
46
+ PERMISSION AND CONDITIONS
47
+ Permission is hereby granted, free of charge, to any person obtaining
48
+ a copy of the Font Software, to use, study, copy, merge, embed, modify,
49
+ redistribute, and sell modified and unmodified copies of the Font
50
+ Software, subject to the following conditions:
51
+
52
+ 1) Neither the Font Software nor any of its individual components,
53
+ in Original or Modified Versions, may be sold by itself.
54
+
55
+ 2) Original or Modified Versions of the Font Software may be bundled,
56
+ redistributed and/or sold with any software, provided that each copy
57
+ contains the above copyright notice and this license. These can be
58
+ included either as stand-alone text files, human-readable headers or
59
+ in the appropriate machine-readable metadata fields within text or
60
+ binary files as long as those fields can be easily viewed by the user.
61
+
62
+ 3) No Modified Version of the Font Software may use the Reserved Font
63
+ Name(s) unless explicit written permission is granted by the corresponding
64
+ Copyright Holder. This restriction only applies to the primary font name as
65
+ presented to the users.
66
+
67
+ 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
68
+ Software shall not be used to promote, endorse or advertise any
69
+ Modified Version, except to acknowledge the contribution(s) of the
70
+ Copyright Holder(s) and the Author(s) or with their explicit written
71
+ permission.
72
+
73
+ 5) The Font Software, modified or unmodified, in part or in whole,
74
+ must be distributed entirely under this license, and must not be
75
+ distributed under any other license. The requirement for fonts to
76
+ remain under this license does not apply to any document created
77
+ using the Font Software.
78
+
79
+ TERMINATION
80
+ This license becomes null and void if any of the above conditions are
81
+ not met.
82
+
83
+ DISCLAIMER
84
+ THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
85
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
86
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
87
+ OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
88
+ COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
89
+ INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
90
+ DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
91
+ FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
92
+ OTHER DEALINGS IN THE FONT SOFTWARE.
@@ -0,0 +1,8 @@
1
+ These unmodified font files are from Inter 4.1, distributed by the upstream
2
+ Inter project under the SIL Open Font License 1.1.
3
+
4
+ - `Inter-Regular.ttf`: Inter 4.1 Regular
5
+ - `Inter-Bold.ttf`: Inter 4.1 Bold
6
+ - License text: `OFL.txt`
7
+ - Upstream release: https://github.com/rsms/inter/releases/tag/v4.1
8
+ - License source: https://github.com/rsms/inter/blob/v4.1/LICENSE.txt
@@ -2,17 +2,23 @@ export function compareReports(current, baseline) {
2
2
  for (const field of ['platform', 'arch', 'cpu']) {
3
3
  if (current[field] !== baseline[field]) throw new Error(`Baseline incompatível: ${field}.`);
4
4
  }
5
- if (current.node.split('.')[0] !== baseline.node?.split('.')[0]) throw new Error('Baseline incompatível: versão principal do Node.');
5
+ if (current.node !== baseline.node) throw new Error('Baseline incompatível: versão exata do Node.');
6
+ if (current.suite !== baseline.suite) throw new Error('Baseline incompatível: suíte.');
7
+ if (baseline.gc !== undefined && current.gc !== baseline.gc) throw new Error('Baseline incompatível: GC explícito.');
6
8
  for (const field of ['iterations', 'samples', 'concurrency']) {
7
9
  if (current.config[field] !== baseline.config?.[field]) throw new Error(`Baseline incompatível: ${field}.`);
8
10
  }
9
- for (const field of ['catalogSize', 'payloadSize', 'soakRounds']) {
11
+ for (const field of ['catalogSize', 'payloadSize', 'soakRounds', 'stateKeys', 'queueSize', 'pageSize', 'fanout', 'warmup']) {
10
12
  if (baseline.config?.[field] !== undefined && current.config[field] !== baseline.config[field]) throw new Error(`Baseline incompatível: ${field}.`);
11
13
  }
12
14
  if (!Array.isArray(baseline.results)) throw new Error('Baseline sem resultados.');
13
15
  return current.results.map(row => {
14
16
  const previous = baseline.results.find(item => item.name === row.name);
15
17
  if (!previous) return { name: row.name, status: 'new' };
18
+ for (const field of ['iterations', 'unitsPerOperation']) {
19
+ if (previous[field] !== undefined && row[field] !== previous[field]) throw new Error(`Baseline incompatível: ${row.name}.${field}.`);
20
+ }
21
+ if (!(row.operationsPerSecond > 0) || !Number.isFinite(row.operationsPerSecond)) throw new Error(`Medição atual inválida: ${row.name}.`);
16
22
  if (!(previous.operationsPerSecond > 0) || !Number.isFinite(previous.operationsPerSecond)) throw new Error(`Baseline inválida: ${row.name}.`);
17
23
  const throughputChangePercent = (row.operationsPerSecond / previous.operationsPerSecond - 1) * 100;
18
24
  return { name: row.name, status: 'compared', throughputChangePercent,
@@ -0,0 +1,66 @@
1
+ import assert from 'node:assert/strict';
2
+ import { performance } from 'node:perf_hooks';
3
+ import { cpus, platform, arch } from 'node:os';
4
+ import { readFile } from 'node:fs/promises';
5
+ import { createHash } from 'node:crypto';
6
+ import { resolve } from 'node:path';
7
+ import { pathToFileURL } from 'node:url';
8
+
9
+ const modules = { current: new URL('../dist/scripting/parser.js', import.meta.url) };
10
+ for (let index = 2; index < process.argv.length; index += 2) {
11
+ const key = { '--parser-module': 'current', '--baseline-module': 'baseline' }[process.argv[index]];
12
+ const value = process.argv[index + 1];
13
+ if (!key || !value || value.startsWith('--')) throw new Error('Uso: node benchmarks/parser.mjs [--parser-module caminho] [--baseline-module caminho]');
14
+ modules[key] = pathToFileURL(resolve(value));
15
+ }
16
+ const implementations = {};
17
+ for (const [label, url] of Object.entries(modules)) implementations[label] = {
18
+ parse: (await import(url)).parse,
19
+ sourceHash: createHash('sha256').update(await readFile(url)).digest('hex'),
20
+ };
21
+ const iterations = 20_000, warmup = 2000, samples = 9, differentialCases = 20_000;
22
+ const cases = {
23
+ plain: 'a'.repeat(8000),
24
+ interpolated: `prefix ${'abc '.repeat(100)}$name suffix ${'xyz '.repeat(100)}`,
25
+ short: '$reply[Olá $username!]',
26
+ dense: '$f[a;b;$g[c]]'.repeat(20),
27
+ };
28
+ const outcome = (parse, source) => {
29
+ try { return parse(source); }
30
+ catch (error) { return { code: error.code, offset: error.offset, message: error.message }; }
31
+ };
32
+ if (implementations.baseline) {
33
+ const alphabet = ['a', '$', '[', ']', ';', '\\', 'é', '\n', '1'];
34
+ for (let seed = 0; seed < differentialCases; seed++) {
35
+ let state = seed + 1, source = '';
36
+ for (let index = 0; index < 50; index++) {
37
+ state = (Math.imul(state, 1664525) + 1013904223) >>> 0;
38
+ source += alphabet[state % alphabet.length];
39
+ }
40
+ assert.deepEqual(outcome(implementations.current.parse, source), outcome(implementations.baseline.parse, source), source);
41
+ }
42
+ }
43
+ const results = [];
44
+ for (const [name, source] of Object.entries(cases)) {
45
+ if (implementations.baseline) assert.deepEqual(implementations.current.parse(source), implementations.baseline.parse(source));
46
+ const times = Object.fromEntries(Object.keys(implementations).map(label => [label, []]));
47
+ for (let sample = 0; sample < samples; sample++) {
48
+ const entries = Object.entries(implementations);
49
+ if (sample % 2) entries.reverse();
50
+ for (const [label, { parse }] of entries) {
51
+ for (let index = 0; index < warmup; index++) parse(source);
52
+ const start = performance.now();
53
+ for (let index = 0; index < iterations; index++) parse(source);
54
+ times[label].push(performance.now() - start);
55
+ }
56
+ }
57
+ for (const [implementation, samplesMs] of Object.entries(times)) {
58
+ const sorted = [...samplesMs].sort((a, b) => a - b);
59
+ results.push({ name, implementation, characters: source.length, iterations, medianMs: sorted[Math.floor(samples / 2)], samplesMs });
60
+ }
61
+ }
62
+ console.log(JSON.stringify({ suite: 'parser', date: new Date().toISOString(), node: process.versions.node,
63
+ platform: platform(), arch: arch(), cpu: cpus()[0]?.model, warmup, samples,
64
+ differentialCases: implementations.baseline ? differentialCases : 0,
65
+ modules: Object.fromEntries(Object.entries(implementations).map(([label, entry]) => [label, { path: modules[label].href, sourceHash: entry.sourceHash }])),
66
+ results }, null, 2));
@@ -0,0 +1,87 @@
1
+ import assert from 'node:assert/strict';
2
+ import { performance } from 'node:perf_hooks';
3
+ import { arch, cpus, platform } from 'node:os';
4
+ import { readFile } from 'node:fs/promises';
5
+ import { resolve } from 'node:path';
6
+ import { fileURLToPath, pathToFileURL } from 'node:url';
7
+ import { compareReports } from './compare.mjs';
8
+
9
+ const config = { iterations: 10_000, samples: 9, concurrency: 1, catalogSize: 1000, payloadSize: 4096, stateKeys: 2000, json: false };
10
+ let packageRoot = fileURLToPath(new URL('../', import.meta.url)), baselinePath;
11
+ for (let i = 2; i < process.argv.length; i++) {
12
+ const key = process.argv[i];
13
+ if (key === '--json') { config.json = true; continue; }
14
+ if (key === '--package-root' || key === '--baseline') {
15
+ const path = process.argv[++i]; if (!path || path.startsWith('--')) throw new Error(`Informe ${key} <caminho>.`);
16
+ if (key === '--package-root') packageRoot = resolve(path); else baselinePath = path;
17
+ continue;
18
+ }
19
+ const name = { '--catalog-size': 'catalogSize', '--payload-size': 'payloadSize', '--state-keys': 'stateKeys' }[key] ?? key.slice(2);
20
+ const max = { iterations: 1_000_000, samples: 50, catalogSize: 10_000, payloadSize: 99_000, stateKeys: 10_000 }[name];
21
+ const value = Number(process.argv[++i]);
22
+ if (!max || !Number.isSafeInteger(value) || value < 1 || value > max) throw new Error(`Opção inválida: ${key}.`);
23
+ config[name] = value;
24
+ }
25
+ const source = pathToFileURL(resolve(packageRoot, 'dist/'));
26
+ source.pathname += source.pathname.endsWith('/') ? '' : '/';
27
+ const { Yuzuha, CommandContext, MemoryStore } = await import(new URL('index.js', source));
28
+ const { MockTransport, mockMessage } = await import(new URL('testing.js', source));
29
+ const manifest = JSON.parse(await readFile(resolve(packageRoot, 'package.json'), 'utf8'));
30
+ const results = [], bots = [];
31
+ const percentile = (values, fraction) => [...values].sort((a, b) => a - b)[Math.ceil(values.length * fraction) - 1];
32
+ async function measure(name, operation, iterations = config.iterations, units = 1) {
33
+ const run = async count => { for (let i = 0; i < count; i++) await operation(); };
34
+ await run(Math.min(iterations, 200)); global.gc?.();
35
+ const before = process.memoryUsage(), samples = [];
36
+ for (let sample = 0; sample < config.samples; sample++) {
37
+ const start = performance.now(); await run(iterations); samples.push(performance.now() - start);
38
+ }
39
+ global.gc?.(); const after = process.memoryUsage();
40
+ results.push({ name, iterations, unitsPerOperation: units, operations: iterations * units * config.samples, concurrency: 1,
41
+ medianMs: percentile(samples, 0.5), p95Ms: percentile(samples, 0.95), samplesMs: samples,
42
+ operationsPerSecond: iterations * units * config.samples / (samples.reduce((sum, value) => sum + value, 0) / 1000),
43
+ heapDeltaBytes: after.heapUsed - before.heapUsed, rssDeltaBytes: after.rss - before.rss });
44
+ }
45
+ function bot() {
46
+ const value = new Yuzuha({ transport: new MockTransport(), store: new MemoryStore(), scheduler: false, http: false }); bots.push(value); return value;
47
+ }
48
+ try {
49
+ const dispatch = bot(); dispatch.command({ name: 'bench', run() {} });
50
+ for (const [name, content, authorBot] of [
51
+ ['ordinary', 'a normal message', false], ['unknown', '!doesNotExist', false], ['bot', '!bench', true],
52
+ ]) {
53
+ const message = mockMessage(content, { authorBot });
54
+ await measure(`dispatch/ignored-${name}`, async () => { assert.equal(await dispatch.handle(message), 'ignored'); });
55
+ }
56
+ const payload = 'x'.repeat(config.payloadSize);
57
+ for (const [name, input] of [['long-input', payload], ['quoted-long-input', `"${payload}"`], ['apostrophe-long-input', `${payload}'suffix`]]) {
58
+ const long = `!bench ${input}`;
59
+ await measure(`dispatch/${name}`, async () => {
60
+ assert.equal(await dispatch.handle(mockMessage(long)), 'success');
61
+ }, Math.max(1, Math.floor(config.iterations / 10)));
62
+ }
63
+ await measure('catalog/register', async () => {
64
+ const registered = new Yuzuha({ transport: new MockTransport(), store: new MemoryStore(), scheduler: false, http: false });
65
+ try {
66
+ for (let i = 0; i < config.catalogSize; i++) registered.command({ name: `item${i}`, run() {} });
67
+ assert.equal(registered.listCommands().length, config.catalogSize);
68
+ } finally { await registered.destroy(); }
69
+ }, 1, config.catalogSize);
70
+ const store = new MemoryStore(), ctx = new CommandContext({ store, command: { name: 'state' },
71
+ message: mockMessage(''), transport: new MockTransport(), cooldown: () => 0 });
72
+ await ctx.data.transaction(data => {
73
+ for (let i = 0; i < config.stateKeys; i++) data.guild.set(`item${i}`, { count: i, tags: ['one', 'two'] });
74
+ });
75
+ const expected = { count: config.stateKeys - 1, tags: ['one', 'two'] };
76
+ await measure('store/read-large-state', async () => {
77
+ assert.deepEqual(await ctx.data.guild.get(`item${config.stateKeys - 1}`), expected);
78
+ }, Math.max(1, Math.floor(config.iterations / 10)));
79
+ const report = { suite: 'performance', version: manifest.version, date: new Date().toISOString(), node: process.versions.node,
80
+ platform: platform(), arch: arch(), cpu: cpus()[0]?.model, gc: typeof global.gc === 'function', config, results };
81
+ if (baselinePath) report.comparison = compareReports(report, JSON.parse(await readFile(baselinePath, 'utf8')));
82
+ console.log(config.json ? JSON.stringify(report, null, 2) : [
83
+ `Yuzuha ${report.version} · Node ${report.node} · ${report.platform}/${report.arch}`,
84
+ ...results.map(row => `${row.name}: ${row.operationsPerSecond.toFixed(0)} ops/s; mediana ${row.medianMs.toFixed(2)}ms`),
85
+ ...(report.comparison ?? []).map(row => `${row.name}: ${row.status === 'new' ? 'novo' : `${row.throughputChangePercent.toFixed(1)}% ante baseline`}`),
86
+ ].join('\n'));
87
+ } finally { await Promise.all(bots.map(value => value.destroy())); }
@@ -0,0 +1,138 @@
1
+ import assert from 'node:assert/strict';
2
+ import { createHash } from 'node:crypto';
3
+ import { readFile } from 'node:fs/promises';
4
+ import { arch, cpus, platform } from 'node:os';
5
+ import { performance } from 'node:perf_hooks';
6
+ import { RateLimits } from '../dist/framework/rate-limits.js';
7
+ import { YuzuhaError } from '../dist/errors.js';
8
+
9
+ // Baseline: src/framework/rate-limits.ts at a227759f726420471ade044a3cf9600a6359a668, with TypeScript types removed.
10
+ class BaselineRateLimits {
11
+ now;
12
+ seen = new Map();
13
+ seenKeys = [];
14
+ seenExpirations = [];
15
+ seenCursor = 0;
16
+ cooldowns = new Map();
17
+ nextSweep = 0;
18
+
19
+ constructor(now = Date.now) { this.now = now; }
20
+
21
+ sweep(time) {
22
+ if (time < this.nextSweep) return;
23
+ for (const [key, until] of this.cooldowns) if (until <= time) this.cooldowns.delete(key);
24
+ this.nextSweep = time + 1000;
25
+ }
26
+
27
+ duplicate(channelID, messageID) {
28
+ const time = this.now();
29
+ this.sweep(time);
30
+ const key = `${channelID.length}:${channelID}${messageID}`;
31
+ if ((this.seen.get(key) ?? 0) > time) return true;
32
+ const previous = this.seenKeys[this.seenCursor];
33
+ if (previous !== undefined && this.seen.get(previous) === this.seenExpirations[this.seenCursor]) this.seen.delete(previous);
34
+ const until = time + 60_000;
35
+ this.seen.set(key, until);
36
+ this.seenKeys[this.seenCursor] = key; this.seenExpirations[this.seenCursor] = until;
37
+ this.seenCursor = (this.seenCursor + 1) % 10_000;
38
+ return false;
39
+ }
40
+
41
+ cooldown(key, duration) {
42
+ const time = this.now();
43
+ this.sweep(time);
44
+ const remaining = (this.cooldowns.get(key) ?? 0) - time;
45
+ if (remaining > 0) return remaining;
46
+ if (this.cooldowns.size >= 100_000) throw new YuzuhaError('COOLDOWN_CAPACITY', 'Capacidade de cooldown excedida.');
47
+ this.cooldowns.set(key, time + duration);
48
+ return 0;
49
+ }
50
+ }
51
+
52
+ const config = { samples: 7, normalIterations: 50_000, loadedIterations: 1000, entries: 25_000,
53
+ warmup: 2000, normalClockStepMs: 0, loadedClockStepMs: 1000, cooldownMs: 1_000_000_000_000 };
54
+ let json = false;
55
+ for (let index = 2; index < process.argv.length; index++) {
56
+ const option = process.argv[index];
57
+ if (option === '--json') { json = true; continue; }
58
+ const name = { '--samples': 'samples', '--normal-iterations': 'normalIterations', '--loaded-iterations': 'loadedIterations', '--entries': 'entries' }[option];
59
+ const value = Number(process.argv[++index]);
60
+ const max = { samples: 50, normalIterations: 90_000, loadedIterations: 100_000, entries: 100_000 }[name];
61
+ if (!max || !Number.isSafeInteger(value) || value < 1 || value > max) throw new Error(`Opção inválida: ${option}.`);
62
+ config[name] = value;
63
+ }
64
+
65
+ const scenarios = [
66
+ { name: 'duplicate/same-tick', operation: 'duplicate', loaded: false },
67
+ { name: 'cooldown/new-same-tick', operation: 'new', loaded: false },
68
+ { name: 'cooldown/active-same-tick', operation: 'active', loaded: false },
69
+ { name: 'duplicate/loaded-clock-steps', operation: 'duplicate', loaded: true },
70
+ { name: 'cooldown/loaded-clock-steps', operation: 'active', loaded: true },
71
+ ];
72
+
73
+ function fixture(Implementation, scenario, iterations) {
74
+ let now = 0;
75
+ const limits = new Implementation(() => now);
76
+ const step = scenario.loaded ? config.loadedClockStepMs : config.normalClockStepMs;
77
+ if (scenario.loaded) for (let index = 0; index < config.entries; index++) limits.cooldown(String(index), config.cooldownMs);
78
+ else if (scenario.operation === 'active') limits.cooldown('0', config.cooldownMs);
79
+ const outputs = new Array(iterations);
80
+ return {
81
+ run() {
82
+ for (let index = 0; index < iterations; index++) {
83
+ now += step;
84
+ outputs[index] = scenario.operation === 'duplicate' ? limits.duplicate('channel', String(index))
85
+ : limits.cooldown(scenario.operation === 'active' ? '0' : String(index), config.cooldownMs);
86
+ }
87
+ },
88
+ validate() {
89
+ for (let index = 0; index < iterations; index++) {
90
+ const expected = scenario.operation === 'duplicate' ? false
91
+ : scenario.operation === 'active' ? config.cooldownMs - step * (index + 1) : 0;
92
+ assert.equal(outputs[index], expected);
93
+ }
94
+ return outputs;
95
+ },
96
+ };
97
+ }
98
+
99
+ const median = values => [...values].sort((a, b) => a - b)[Math.ceil(values.length / 2) - 1];
100
+ const summarize = (samplesMs, iterations) => ({ samplesMs, medianMs: median(samplesMs),
101
+ operationsPerSecond: iterations * samplesMs.length / (samplesMs.reduce((sum, value) => sum + value, 0) / 1000) });
102
+ const implementations = [['baseline', BaselineRateLimits], ['current', RateLimits]];
103
+ const results = [];
104
+ for (const scenario of scenarios) {
105
+ const iterations = scenario.loaded ? config.loadedIterations : config.normalIterations;
106
+ for (const [, Implementation] of implementations) {
107
+ const warmup = fixture(Implementation, scenario, Math.min(config.warmup, iterations));
108
+ warmup.run(); warmup.validate();
109
+ }
110
+ const samples = { baseline: [], current: [] };
111
+ for (let sample = 0; sample < config.samples; sample++) {
112
+ const outputs = {};
113
+ for (const [name, Implementation] of sample % 2 ? [...implementations].reverse() : implementations) {
114
+ const trial = fixture(Implementation, scenario, iterations);
115
+ global.gc?.();
116
+ const start = performance.now();
117
+ trial.run();
118
+ samples[name].push(performance.now() - start);
119
+ outputs[name] = trial.validate();
120
+ }
121
+ assert.deepEqual(outputs.current, outputs.baseline);
122
+ }
123
+ const baseline = summarize(samples.baseline, iterations), current = summarize(samples.current, iterations);
124
+ results.push({ name: scenario.name, iterations, entries: scenario.loaded ? config.entries : scenario.operation === 'active' ? 1 : 0,
125
+ clockStepMs: scenario.loaded ? config.loadedClockStepMs : config.normalClockStepMs, baseline, current,
126
+ medianChangePercent: (current.medianMs / baseline.medianMs - 1) * 100 });
127
+ }
128
+ const hash = input => createHash('sha256').update(input).digest('hex');
129
+ const report = { suite: 'rate-limits', date: new Date().toISOString(), node: process.versions.node, platform: platform(), arch: arch(),
130
+ cpu: cpus()[0]?.model, gc: typeof global.gc === 'function', baselineCommit: 'a227759f726420471ade044a3cf9600a6359a668',
131
+ sourceHashes: { baselineImplementation: hash(BaselineRateLimits.toString()), currentDist: hash(await readFile(new URL('../dist/framework/rate-limits.js', import.meta.url))),
132
+ benchmark: hash(await readFile(new URL(import.meta.url))) }, config,
133
+ scope: 'Local synthetic workloads; advancing the fake clock simulates sweep boundaries, not wall-clock throughput of a bot.', results };
134
+ console.log(json ? JSON.stringify(report, null, 2) : [
135
+ `RateLimits · Node ${report.node} · ${report.cpu} · ${report.platform}/${report.arch}`,
136
+ report.scope,
137
+ ...results.map(row => `${row.name}: ${row.baseline.medianMs.toFixed(3)} -> ${row.current.medianMs.toFixed(3)} ms; ${row.iterations} operations; clock +${row.clockStepMs} ms/operation`),
138
+ ].join('\n'));
@@ -0,0 +1,99 @@
1
+ import assert from 'node:assert/strict';
2
+ import { performance } from 'node:perf_hooks';
3
+ import { arch, cpus, platform } from 'node:os';
4
+ import { readFile } from 'node:fs/promises';
5
+ import { resolve } from 'node:path';
6
+ import { fileURLToPath, pathToFileURL } from 'node:url';
7
+ import { compareReports } from './compare.mjs';
8
+ import { createHash } from 'node:crypto';
9
+
10
+ const config = { iterations: 10_000, samples: 7, warmup: 2000, queueSize: 5000, pageSize: 25, fanout: 32, concurrency: 1, json: false };
11
+ let packageRoot = fileURLToPath(new URL('../', import.meta.url)), baselinePath;
12
+ for (let index = 2; index < process.argv.length; index++) {
13
+ const key = process.argv[index];
14
+ if (key === '--json') { config.json = true; continue; }
15
+ if (key === '--package-root' || key === '--baseline') {
16
+ const value = process.argv[++index]; if (!value || value.startsWith('--')) throw new Error(`Informe ${key} <caminho>.`);
17
+ if (key === '--package-root') packageRoot = resolve(value); else baselinePath = value;
18
+ continue;
19
+ }
20
+ const name = { '--queue-size': 'queueSize', '--page-size': 'pageSize' }[key] ?? key.slice(2);
21
+ const max = { iterations: 1_000_000, samples: 50, warmup: 100_000, queueSize: 100_000, pageSize: 1000, fanout: 128 }[name];
22
+ const value = Number(process.argv[++index]);
23
+ if (!max || !Number.isSafeInteger(value) || value < 1 || value > max) throw new Error(`Opção inválida: ${key}.`);
24
+ config[name] = value;
25
+ }
26
+ if (config.pageSize > config.queueSize) throw new Error('pageSize deve caber na fila.');
27
+ const source = pathToFileURL(resolve(packageRoot, 'dist') + '/');
28
+ const { Yuzuha, MemoryStore } = await import(new URL('index.js', source));
29
+ const { MusicManager, LavalinkNode } = await import(new URL('music.js', source));
30
+ const { MockTransport, MockMusicBackend, mockMessage, mockTrack } = await import(new URL('testing.js', source));
31
+ const { parseFlags } = await import(new URL('commands/arguments.js', source));
32
+ const manifest = JSON.parse(await readFile(resolve(packageRoot, 'package.json'), 'utf8'));
33
+ const sourceHashes = {};
34
+ for (const path of ['commands/arguments.js', 'domain/track-queue.js', 'domain/music-state.js', 'services/music.js', 'services/music-player.js', 'infrastructure/lavalink/node.js', 'infrastructure/lavalink/protocol.js']) {
35
+ try { sourceHashes[path] = createHash('sha256').update(await readFile(new URL(path, source))).digest('hex'); }
36
+ catch (error) { if (error.code !== 'ENOENT') throw error; sourceHashes[path] = null; }
37
+ }
38
+ const results = [];
39
+ const percentile = (values, fraction) => [...values].sort((a, b) => a - b)[Math.ceil(values.length * fraction) - 1];
40
+ async function measure(name, operation, iterations = config.iterations, metrics) {
41
+ const run = async count => { for (let index = 0; index < count; index++) await operation(); };
42
+ await run(Math.min(iterations, config.warmup)); global.gc?.();
43
+ const before = process.memoryUsage(), samples = [], initial = metrics?.();
44
+ for (let sample = 0; sample < config.samples; sample++) {
45
+ const start = performance.now(); await run(iterations); samples.push(performance.now() - start);
46
+ }
47
+ global.gc?.(); const after = process.memoryUsage(), operations = iterations * config.samples;
48
+ results.push({ name, iterations, operations, unitsPerOperation: 1, concurrency: 1,
49
+ medianMs: percentile(samples, 0.5), p95Ms: percentile(samples, 0.95), samplesMs: samples,
50
+ operationsPerSecond: operations / (samples.reduce((sum, value) => sum + value, 0) / 1000),
51
+ heapDeltaBytes: after.heapUsed - before.heapUsed, rssDeltaBytes: after.rss - before.rss,
52
+ ...(metrics ? { backendRequests: metrics() - initial, backendRequestsPerOperation: (metrics() - initial) / operations } : {}),
53
+ });
54
+ }
55
+ const flags = [
56
+ { name: 'count', type: 'integer', min: 1, max: 20 }, { name: 'verbose', type: 'boolean', aliases: ['v'] },
57
+ { name: 'speed', type: 'number', defaultValue: 1 }, { name: 'timeout', type: 'duration' },
58
+ { name: 'label', type: 'string' }, { name: 'owner', type: 'user' }, { name: 'format', defaultValue: 'opus', choices: ['opus', 'webm'] },
59
+ ];
60
+ const tokens = ['tune', '--count', '3', '-v', '--speed=1.25', '--timeout', '2s', '--label=lofi mix', '--owner', '12345678901234567'];
61
+ const bot = new Yuzuha({ transport: new MockTransport(), store: new MemoryStore(), scheduler: false, http: false });
62
+ const manager = new MusicManager({ nodes: [new MockMusicBackend()], queueLimit: config.queueSize });
63
+ let backendRequests = 0;
64
+ const node = new LavalinkNode({ url: 'http://localhost:2333', password: 'offline', userID: '123', cache: false, reconnect: false,
65
+ maxPendingRequests: config.fanout, socketFactory() { throw new Error('Benchmark offline não conecta ao gateway.'); },
66
+ fetch: async () => {
67
+ backendRequests++; await new Promise(resolve => setImmediate(resolve));
68
+ return Response.json({ loadType: 'track', data: mockTrack('result') });
69
+ },
70
+ });
71
+ try {
72
+ await measure('arguments/typed-flags', () => {
73
+ const result = parseFlags(flags, tokens); assert.equal(result.flags.get('count'), 3); assert.equal(result.flags.get('format'), 'opus');
74
+ });
75
+ bot.command({ name: 'bench', flags, run(ctx) { assert.equal(ctx.flags.get('count'), 3); assert.equal(ctx.flags.get('label'), 'lofi mix'); } });
76
+ await measure('dispatch/typed-flags', async () => {
77
+ assert.equal(await bot.handle(mockMessage('!bench tune --count 3 -v --speed=1.25 --timeout 2s --label="lofi mix" --owner 12345678901234567')), 'success');
78
+ });
79
+ const player = manager.createPlayer('100'); player.enqueue(Array.from({ length: config.queueSize }, (_, index) => mockTrack(String(index))));
80
+ const start = Math.min(Math.floor(config.queueSize / 2), config.queueSize - config.pageSize);
81
+ await measure('music/queue-page', () => {
82
+ const page = typeof player.queuePage === 'function' ? player.queuePage(start, config.pageSize) : player.queue.slice(start, start + config.pageSize);
83
+ assert.equal(page.length, config.pageSize); assert.equal(page[0].encoded, String(start));
84
+ }, Math.max(1, Math.floor(config.iterations / 100)));
85
+ let batch = 0;
86
+ await measure('music/signaled-search-fanout', async () => {
87
+ const identifier = `scsearch:batch${++batch}`;
88
+ const results = await Promise.all(Array.from({ length: config.fanout }, () => node.loadTracks(identifier, new AbortController().signal)));
89
+ assert.equal(results.length, config.fanout); assert.equal(results[0].loadType, 'track');
90
+ }, Math.max(1, Math.floor(config.iterations / 100)), () => backendRequests);
91
+ const report = { suite: 'refinement', version: manifest.version, date: new Date().toISOString(), node: process.versions.node,
92
+ platform: platform(), arch: arch(), cpu: cpus()[0]?.model, gc: typeof global.gc === 'function', sourceHashes, config, results };
93
+ if (baselinePath) report.comparison = compareReports(report, JSON.parse(await readFile(baselinePath, 'utf8')));
94
+ console.log(config.json ? JSON.stringify(report, null, 2) : [
95
+ `Yuzuha ${report.version} · Node ${report.node} · ${report.platform}/${report.arch}`,
96
+ ...results.map(row => `${row.name}: ${row.operationsPerSecond.toFixed(0)} ops/s; mediana ${row.medianMs.toFixed(2)}ms${row.backendRequests === undefined ? '' : `; ${row.backendRequestsPerOperation} requisições simuladas/lote`}`),
97
+ ...(report.comparison ?? []).map(row => `${row.name}: ${row.status === 'new' ? 'novo' : `${row.throughputChangePercent.toFixed(1)}% ante baseline`}`),
98
+ ].join('\n'));
99
+ } finally { await bot.destroy(); await manager.close(); await node.close(); }