@isdk/ai-tool 0.4.0 → 0.5.1

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 (344) hide show
  1. package/dist/chunk-VIG2GB47.mjs +39 -1
  2. package/dist/chunk-VJ45JQBR.mjs +7829 -0
  3. package/dist/funcs.d.mts +3 -2
  4. package/dist/funcs.d.ts +3 -2
  5. package/dist/funcs.js +5156 -1
  6. package/dist/funcs.mjs +29 -1
  7. package/dist/index-Br-4ZYgE.d.mts +892 -0
  8. package/dist/index-Br-4ZYgE.d.ts +892 -0
  9. package/dist/index.d.mts +204 -237
  10. package/dist/index.d.ts +204 -237
  11. package/dist/index.js +8132 -1
  12. package/dist/index.mjs +476 -1
  13. package/dist/test/util.js +101 -1
  14. package/dist/test/util.mjs +30 -1
  15. package/docs/README.md +1 -1
  16. package/docs/classes/AbortError.md +80 -82
  17. package/docs/classes/AlreadyExistsError.md +80 -82
  18. package/docs/classes/BaseError.md +81 -81
  19. package/docs/classes/BinarySemaphore.md +418 -0
  20. package/docs/classes/CancelableAbility.md +193 -105
  21. package/docs/classes/ClientTools.md +655 -631
  22. package/docs/classes/CommonError.md +85 -85
  23. package/docs/classes/ConfigFile.md +131 -111
  24. package/docs/classes/EnvPromptTemplate.md +1158 -0
  25. package/docs/classes/EventClient.md +766 -736
  26. package/docs/classes/EventEmitter.md +299 -0
  27. package/docs/classes/EventServer.md +783 -757
  28. package/docs/classes/EventToolFunc.md +612 -588
  29. package/docs/classes/FStringPromptTemplate.md +246 -238
  30. package/docs/classes/FewShotPromptTemplate.md +240 -246
  31. package/docs/classes/GolangPromptTemplate.md +246 -238
  32. package/docs/classes/HFEnvironment.md +42 -44
  33. package/docs/classes/HFInterpreter.md +22 -20
  34. package/docs/classes/HFTemplate.md +19 -19
  35. package/docs/classes/HfPromptTemplate.md +246 -238
  36. package/docs/classes/IntSet.md +53 -53
  37. package/docs/classes/LRUCache.md +601 -0
  38. package/docs/classes/NotFoundError.md +80 -82
  39. package/docs/classes/NotImplementationError.md +80 -82
  40. package/docs/classes/PromptExampleSelector.md +39 -39
  41. package/docs/classes/PromptTemplate.md +235 -226
  42. package/docs/classes/ReadableStreamError.md +82 -84
  43. package/docs/classes/ResClientTools.md +662 -630
  44. package/docs/classes/ResServerTools.md +648 -626
  45. package/docs/classes/SSEChannel.md +61 -61
  46. package/docs/classes/Semaphore.md +401 -40
  47. package/docs/classes/ServerTools.md +622 -608
  48. package/docs/classes/SignalGate.md +182 -0
  49. package/docs/classes/TaskAbortController.md +27 -33
  50. package/docs/classes/ToolFunc.md +582 -552
  51. package/docs/classes/YamlTypeBaseObject.md +9 -7
  52. package/docs/enumerations/AsyncFeatureBits.md +6 -10
  53. package/docs/enumerations/AsyncFeatures.md +6 -10
  54. package/docs/enumerations/ErrorCode.md +24 -64
  55. package/docs/enumerations/HashAlgorithm.md +14 -34
  56. package/docs/functions/AIArgProcessor.md +15 -9
  57. package/docs/functions/AIStream.md +9 -7
  58. package/docs/functions/ChoiceArgProcessor.md +15 -9
  59. package/docs/functions/ObjectArgsToArgsInfo.md +29 -0
  60. package/docs/functions/RateLimit.md +13 -9
  61. package/docs/functions/TemplateArgProcessor.md +15 -9
  62. package/docs/functions/assignDirs.md +33 -0
  63. package/docs/functions/backendEventable.md +14 -8
  64. package/docs/functions/beforeShutdown.md +29 -0
  65. package/docs/functions/canonicalize.md +6 -6
  66. package/docs/functions/completeSentences.md +9 -7
  67. package/docs/functions/concatText.md +8 -6
  68. package/docs/functions/countLLMTokens.md +9 -7
  69. package/docs/functions/countRegexMatches.md +9 -7
  70. package/docs/functions/createAbilityInjector.md +66 -34
  71. package/docs/functions/createCallbacksTransformer.md +6 -6
  72. package/docs/functions/createEmptyReadableStream.md +3 -5
  73. package/docs/functions/createEndWithRepetitionDetector.md +9 -7
  74. package/docs/functions/createError.md +12 -8
  75. package/docs/functions/createEventStreamTransformer.md +8 -8
  76. package/docs/functions/createHfValueFunc.md +9 -7
  77. package/docs/functions/createLRUCache.md +9 -7
  78. package/docs/functions/createYamlObjectTag.md +9 -7
  79. package/docs/functions/dateToText.md +9 -7
  80. package/docs/functions/decodeCharset.md +9 -7
  81. package/docs/functions/detectCharset.md +9 -7
  82. package/docs/functions/encodeLLMTokens.md +9 -7
  83. package/docs/functions/ensureQuoted.md +25 -0
  84. package/docs/functions/eventable.md +82 -0
  85. package/docs/functions/expandConfig.md +25 -0
  86. package/docs/functions/expandEnv.md +6 -6
  87. package/docs/functions/expandObjEnv.md +12 -8
  88. package/docs/functions/expandPath.md +25 -0
  89. package/docs/functions/extNameLevel.md +6 -6
  90. package/docs/functions/fileIsExists.md +6 -6
  91. package/docs/functions/filenameReservedRegex.md +3 -5
  92. package/docs/functions/filterValidFnScope.md +6 -6
  93. package/docs/functions/findIndexNonEmptyFrom.md +9 -7
  94. package/docs/functions/findPort.md +9 -7
  95. package/docs/functions/formatISO.md +9 -11
  96. package/docs/functions/formatTextWithSpace.md +13 -9
  97. package/docs/functions/getAllEnumKeys.md +8 -8
  98. package/docs/functions/getConfigFileNames.md +9 -7
  99. package/docs/functions/getConfigs.md +9 -7
  100. package/docs/functions/getEnvVairables.md +21 -0
  101. package/docs/functions/getFileMetaInfo.md +6 -6
  102. package/docs/functions/getHashAlgoBySize.md +6 -6
  103. package/docs/functions/getKeysPath.md +6 -6
  104. package/docs/functions/getLLMTokenizer.md +6 -6
  105. package/docs/functions/getMultiLevelExtname.md +9 -7
  106. package/docs/functions/getPackageDir.md +6 -6
  107. package/docs/functions/getRealFilepath.md +6 -6
  108. package/docs/functions/getResponseErrorReadableStream.md +6 -6
  109. package/docs/functions/getXDGConfigs.md +37 -0
  110. package/docs/functions/hasDirectoryIn.md +9 -7
  111. package/docs/functions/hash.md +25 -0
  112. package/docs/functions/hashFile.md +10 -8
  113. package/docs/functions/hashStream.md +10 -8
  114. package/docs/functions/hfParse.md +6 -6
  115. package/docs/functions/hfTokenize.md +9 -7
  116. package/docs/functions/initShutdown.md +15 -0
  117. package/docs/functions/interpolateEnv.md +13 -9
  118. package/docs/functions/interpolateFString.md +9 -7
  119. package/docs/functions/interpolateGolangTemplate.md +12 -8
  120. package/docs/functions/isLangUsingSpaces.md +6 -6
  121. package/docs/functions/isListItemString.md +6 -6
  122. package/docs/functions/isModelNameMatched.md +9 -7
  123. package/docs/functions/isPunctuationChar.md +6 -6
  124. package/docs/functions/isQuoted.md +21 -0
  125. package/docs/functions/isRegExp.md +6 -6
  126. package/docs/functions/isSameString.md +36 -0
  127. package/docs/functions/isSectionString.md +9 -7
  128. package/docs/functions/isSentenceEnding.md +6 -6
  129. package/docs/functions/isSepLineString.md +6 -6
  130. package/docs/functions/isStrWrapped.md +25 -0
  131. package/docs/functions/isSubdirectory.md +9 -7
  132. package/docs/functions/isTitleString.md +9 -7
  133. package/docs/functions/isValidFilename.md +6 -6
  134. package/docs/functions/isValidFilepath.md +6 -6
  135. package/docs/functions/isWebStream.md +6 -6
  136. package/docs/functions/jsonFilterToWhere.md +9 -7
  137. package/docs/functions/jsonToMarkdownStr.md +18 -10
  138. package/docs/functions/loadAIConfig.md +21 -0
  139. package/docs/functions/loadConfig.md +25 -0
  140. package/docs/functions/loadConfigFile.md +25 -0
  141. package/docs/functions/loadFileFromPaths.md +24 -14
  142. package/docs/functions/loadTextFromPaths.md +18 -10
  143. package/docs/functions/lrucache.md +17 -11
  144. package/docs/functions/makeToolFuncCancelable.md +14 -8
  145. package/docs/functions/matchUrlProtocol.md +6 -6
  146. package/docs/functions/memoize.md +9 -7
  147. package/docs/functions/messagesToText.md +6 -6
  148. package/docs/functions/paramsSizeToScaleStr.md +9 -7
  149. package/docs/functions/parseCommand.md +13 -9
  150. package/docs/functions/parseDateFormat.md +15 -13
  151. package/docs/functions/parseFString.md +6 -6
  152. package/docs/functions/parseISO.md +9 -11
  153. package/docs/functions/parseJsJson.md +9 -7
  154. package/docs/functions/parseJsJsonSimpleSync.md +9 -7
  155. package/docs/functions/parseObjectArgInfo.md +15 -9
  156. package/docs/functions/parseObjectArgumentInfos.md +12 -8
  157. package/docs/functions/parseObjectArguments.md +12 -8
  158. package/docs/functions/parseObjectArgumentsAsArgInfos.md +12 -8
  159. package/docs/functions/parseYaml.md +11 -7
  160. package/docs/functions/quoteStr.md +6 -6
  161. package/docs/functions/reControlCharsRegex.md +3 -5
  162. package/docs/functions/readFilenamesRecursiveSync.md +16 -10
  163. package/docs/functions/readTextFileChunks.md +9 -7
  164. package/docs/functions/readTextFileChunksEx.md +9 -7
  165. package/docs/functions/readableFromAsyncIterable.md +6 -6
  166. package/docs/functions/registerCoreTools.md +3 -5
  167. package/docs/functions/registerYamlTag.md +6 -6
  168. package/docs/functions/removeMarkdownBold.md +9 -7
  169. package/docs/functions/removeMarkdownBoldAndItalic.md +9 -7
  170. package/docs/functions/removeMarkdownItalic.md +9 -7
  171. package/docs/functions/replaceWithPlaceholder.md +11 -9
  172. package/docs/functions/restoreFromPlacehoders.md +12 -8
  173. package/docs/functions/sanitizeFilename.md +9 -7
  174. package/docs/functions/sanitizeFilepath.md +9 -7
  175. package/docs/functions/saveConfigFile.md +12 -8
  176. package/docs/functions/scaleStrToParamsSize.md +6 -6
  177. package/docs/functions/shutdown.md +33 -0
  178. package/docs/functions/simplifyObjectArguments.md +6 -6
  179. package/docs/functions/sortedValues.md +6 -6
  180. package/docs/functions/splitChunks.md +9 -7
  181. package/docs/functions/splitParagraph.md +9 -7
  182. package/docs/functions/splitSentence.md +9 -7
  183. package/docs/functions/stringifyYaml.md +11 -7
  184. package/docs/functions/stripConsoleColor.md +6 -6
  185. package/docs/functions/textToDate.md +9 -7
  186. package/docs/functions/throwError.md +12 -8
  187. package/docs/functions/toDate.md +9 -11
  188. package/docs/functions/toDateTime.md +6 -6
  189. package/docs/functions/toRegExp.md +6 -6
  190. package/docs/functions/trimStartOfStreamHelper.md +6 -6
  191. package/docs/functions/truncTo.md +12 -8
  192. package/docs/functions/truncateByToken.md +9 -7
  193. package/docs/functions/truncateToTokenLimit.md +9 -7
  194. package/docs/functions/truncateToTokenLimitEx.md +9 -7
  195. package/docs/functions/uuid.md +9 -7
  196. package/docs/functions/uuidParse.md +6 -6
  197. package/docs/functions/uuidStringify.md +10 -8
  198. package/docs/functions/uuidValidate.md +6 -6
  199. package/docs/functions/uuidVersion.md +6 -6
  200. package/docs/functions/uuidv1.md +28 -20
  201. package/docs/functions/uuidv4.md +28 -20
  202. package/docs/functions/uuidv5.md +34 -22
  203. package/docs/functions/wait.md +6 -6
  204. package/docs/functions/wrapEventEmitter.md +27 -0
  205. package/docs/functions/xxhash.md +12 -8
  206. package/docs/functions/xxhash32.md +9 -7
  207. package/docs/functions/xxhash64.md +9 -7
  208. package/docs/functions/xxhashAsStr.md +12 -8
  209. package/docs/globals.md +45 -1
  210. package/docs/interfaces/AIChatAssistantMessageParam.md +42 -30
  211. package/docs/interfaces/AIChatContentPartImage.md +6 -8
  212. package/docs/interfaces/AIChatContentPartText.md +5 -7
  213. package/docs/interfaces/AIChatMessageParamBase.md +23 -13
  214. package/docs/interfaces/AIChatMessageToolCall.md +7 -11
  215. package/docs/interfaces/AIChatSystemMessageParam.md +40 -22
  216. package/docs/interfaces/AIChatToolChoiceFuncObject.md +37 -0
  217. package/docs/interfaces/AIChatToolChoiceObject.md +25 -0
  218. package/docs/interfaces/AIChatToolFunc.md +41 -0
  219. package/docs/interfaces/AIChatToolFuncParam.md +37 -0
  220. package/docs/interfaces/AIChatToolMessageParam.md +40 -24
  221. package/docs/interfaces/AIChatToolParam.md +25 -0
  222. package/docs/interfaces/AIChatToolTypeObject.md +17 -0
  223. package/docs/interfaces/AIChatUserMessageParam.md +44 -34
  224. package/docs/interfaces/AIChoiceConfig.md +10 -22
  225. package/docs/interfaces/AIResult.md +13 -21
  226. package/docs/interfaces/AIStreamParser.md +11 -7
  227. package/docs/interfaces/AIStreamParserOptions.md +5 -5
  228. package/docs/interfaces/BaseFunc.md +30 -40
  229. package/docs/interfaces/BaseFuncItem.md +18 -28
  230. package/docs/interfaces/BinarySemaphoreAcquireOptions.md +25 -0
  231. package/docs/interfaces/BinarySemaphoreOptions.md +57 -0
  232. package/docs/interfaces/BinarySemaphoreReleaseOptions.md +25 -0
  233. package/docs/interfaces/BinarySemaphoreReleaserFunc.md +37 -0
  234. package/docs/interfaces/CancelableAbilityOptions.md +27 -29
  235. package/docs/interfaces/ClientFuncItem.md +31 -47
  236. package/docs/interfaces/DotenvExpandOptions.md +8 -12
  237. package/docs/interfaces/DotenvExpandOutput.md +5 -7
  238. package/docs/interfaces/DotenvParseInput.md +4 -2
  239. package/docs/interfaces/DotenvParseOutput.md +4 -2
  240. package/docs/interfaces/DotenvPopulateInput.md +4 -2
  241. package/docs/interfaces/EventClientFuncParams.md +11 -15
  242. package/docs/interfaces/EventServerFuncParams.md +14 -18
  243. package/docs/interfaces/FewShotPromptTemplateOptions.md +29 -45
  244. package/docs/interfaces/FuncItem.md +26 -38
  245. package/docs/interfaces/FuncParam.md +11 -21
  246. package/docs/interfaces/FuncParams.md +4 -2
  247. package/docs/interfaces/Funcs.md +4 -2
  248. package/docs/interfaces/HashAlgoParams.md +6 -10
  249. package/docs/interfaces/IFileMetaInfo.md +10 -22
  250. package/docs/interfaces/IReadTextFileChunksOptions.md +29 -43
  251. package/docs/interfaces/ITruncateToTokenLimitOptions.md +19 -31
  252. package/docs/interfaces/JsonFilter.md +4 -2
  253. package/docs/interfaces/ParseObjectArgumentOptions.md +13 -31
  254. package/docs/interfaces/PromptExampleSelectorOptions.md +8 -10
  255. package/docs/interfaces/PromptTemplateOptions.md +10 -20
  256. package/docs/interfaces/RemoteFuncItem.md +28 -44
  257. package/docs/interfaces/ReplacePlacehoderOptions.md +7 -13
  258. package/docs/interfaces/ResClientFuncParams.md +10 -8
  259. package/docs/interfaces/ResServerFuncParams.md +15 -19
  260. package/docs/interfaces/SanitizeFilenameOptions.md +5 -7
  261. package/docs/interfaces/SectionStringOptions.md +5 -7
  262. package/docs/interfaces/SemaphoreOptions.md +89 -0
  263. package/docs/interfaces/SemaphoreTaskItem.md +73 -0
  264. package/docs/interfaces/ServerFuncItem.md +32 -50
  265. package/docs/interfaces/ServerFuncParams.md +6 -8
  266. package/docs/interfaces/SplitSentenceOptions.md +7 -13
  267. package/docs/interfaces/StreamCallbacksAndOptions.md +26 -22
  268. package/docs/interfaces/TaskAbortControllers.md +4 -2
  269. package/docs/interfaces/TaskPromise.md +24 -24
  270. package/docs/interfaces/ToolFuncPackage.md +11 -13
  271. package/docs/namespaces/EventStates/README.md +14 -0
  272. package/docs/namespaces/EventStates/variables/ABORT.md +11 -0
  273. package/docs/namespaces/EventStates/variables/CONTINUE.md +11 -0
  274. package/docs/namespaces/EventStates/variables/DONE.md +11 -0
  275. package/docs/namespaces/EventStates/variables/STOPPED.md +11 -0
  276. package/docs/namespaces/uuidv5/README.md +12 -0
  277. package/docs/namespaces/uuidv5/variables/DNS.md +11 -0
  278. package/docs/namespaces/uuidv5/variables/URL.md +11 -0
  279. package/docs/type-aliases/AIChatContentPart.md +2 -4
  280. package/docs/type-aliases/AIChatMessageParam.md +3 -5
  281. package/docs/type-aliases/AIChatRole.md +2 -4
  282. package/docs/type-aliases/AIChatToolChoiceParam.md +11 -0
  283. package/docs/type-aliases/AIMessageType.md +2 -4
  284. package/docs/type-aliases/AIModelNameRule.md +2 -4
  285. package/docs/type-aliases/AIModelNameRuleFn.md +6 -6
  286. package/docs/type-aliases/AIModelNameRules.md +2 -4
  287. package/docs/type-aliases/AITextGenerationFinishReason.md +2 -4
  288. package/docs/type-aliases/ActionName.md +2 -4
  289. package/docs/type-aliases/AsyncTaskId.md +2 -4
  290. package/docs/type-aliases/BeforeShutdownListener.md +23 -0
  291. package/docs/type-aliases/EventErrorListenerFn.md +15 -9
  292. package/docs/type-aliases/EventListenerFn.md +12 -8
  293. package/docs/type-aliases/FStringPromptTemplateNode.md +4 -6
  294. package/docs/type-aliases/FuncParamType.md +2 -4
  295. package/docs/type-aliases/PromptExamples.md +3 -5
  296. package/docs/type-aliases/PromptTemplateType.md +2 -4
  297. package/docs/type-aliases/PromptType.md +2 -4
  298. package/docs/type-aliases/SemaphoreIsReadyFuncType.md +15 -0
  299. package/docs/type-aliases/TFunc.md +9 -7
  300. package/docs/variables/AIChatRoles.md +3 -5
  301. package/docs/variables/AIMessageTypes.md +3 -5
  302. package/docs/variables/AITextGenerationFinishReasons.md +3 -5
  303. package/docs/variables/AbortErrorCode.md +2 -4
  304. package/docs/variables/ActionNames.md +3 -5
  305. package/docs/variables/AlreadyExistsErrorCode.md +2 -4
  306. package/docs/variables/ClientToolFuncSchema.md +40 -26
  307. package/docs/variables/DEFAULT_CONFIG_NAME.md +11 -0
  308. package/docs/variables/DefaultAsyncSemaphoreCapacity.md +2 -4
  309. package/docs/variables/EventBusName.md +2 -4
  310. package/docs/variables/EventName.md +2 -4
  311. package/docs/variables/FilenameReservedRegex.md +3 -5
  312. package/docs/variables/HFBuiltins.md +42 -12
  313. package/docs/variables/InternalErrorCode.md +2 -4
  314. package/docs/variables/LLM_TOKENIZER_NAMES.md +5 -7
  315. package/docs/variables/LLM_TOKENIZER_NAMES_MAP.md +2 -4
  316. package/docs/variables/NotFoundErrorCode.md +2 -4
  317. package/docs/variables/NotImplementedErrorCode.md +2 -4
  318. package/docs/variables/PASSING_SCORE.md +2 -4
  319. package/docs/variables/PromptTemplateTypes.md +3 -5
  320. package/docs/variables/PromptTypes.md +4 -6
  321. package/docs/variables/RStreamErrCode.md +2 -4
  322. package/docs/variables/RemoteToolFuncSchema.md +40 -26
  323. package/docs/variables/ResponseRStreamErrCode.md +2 -4
  324. package/docs/variables/SHUTDOWN_SIGNALS.md +17 -0
  325. package/docs/variables/SSEChannelAlreadyClosedErrCode.md +2 -4
  326. package/docs/variables/SecondaryCache.md +11 -0
  327. package/docs/variables/ServerToolFuncSchema.md +40 -26
  328. package/docs/variables/ToolAsyncCancelableBit.md +2 -4
  329. package/docs/variables/ToolAsyncMultiTaskBit.md +2 -4
  330. package/docs/variables/ToolAsyncPriorityBit.md +2 -4
  331. package/docs/variables/ToolFuncSchema.md +33 -25
  332. package/docs/variables/WindowsReservedNameRegex.md +3 -5
  333. package/docs/variables/base32768.md +2 -4
  334. package/docs/variables/defaultTemplateFormat.md +2 -4
  335. package/docs/variables/event.md +2 -4
  336. package/docs/variables/eventClient.md +2 -4
  337. package/docs/variables/eventServer.md +2 -4
  338. package/docs/variables/lrucache.md +2 -4
  339. package/docs/variables/mimeType.md +2 -4
  340. package/docs/variables/uuidNIL.md +3 -5
  341. package/package.json +31 -31
  342. package/dist/chunk-SIP3XWIH.mjs +0 -1
  343. package/dist/index-BC3GQn6-.d.mts +0 -488
  344. package/dist/index-BC3GQn6-.d.ts +0 -488
@@ -1,4 +1,4 @@
1
- [**@isdk/ai-tool**](../README.md) • **Docs**
1
+ [**@isdk/ai-tool**](../README.md)
2
2
 
3
3
  ***
4
4
 
@@ -6,8 +6,11 @@
6
6
 
7
7
  # Class: Semaphore
8
8
 
9
+ Defined in: [packages/ai-tool/src/utils/async-semaphore.ts:372](https://github.com/isdk/ai-tool.js/blob/6a89194ac34437a1bc58f7ec590cd22976939ca6/src/utils/async-semaphore.ts#L372)
10
+
9
11
  A Semaphore implementation for managing concurrency in asynchronous operations.
10
12
  Semaphores allow a fixed number of resources to be accessed concurrently.
13
+ This class extends BinarySemaphore and adds support for a maximum concurrency limit and an optional readiness check.
11
14
 
12
15
  Example usage:
13
16
 
@@ -17,7 +20,17 @@ const semaphore = new Semaphore(5); // Allows 5 concurrent operations.
17
20
  const semaphore = new Semaphore(
18
21
  4, // Allow 4 concurrent async calls
19
22
  {
20
- capacity: 100 // Prealloc space for 100 tokens
23
+ capacity: 100, // Prealloc space for 100 tokens
24
+ isReadyFn: async () => {
25
+ // Check if the system is ready to handle more requests
26
+ return true;
27
+ },
28
+ pauseFn: () => {
29
+ console.log('Pausing the stream');
30
+ },
31
+ resumeFn: () => {
32
+ console.log('Resuming the stream');
33
+ }
21
34
  }
22
35
  );
23
36
 
@@ -34,77 +47,317 @@ async function fetchData(x) {
34
47
  const data = await Promise.all(array.map(fetchData));
35
48
  ```
36
49
 
50
+ ## Extends
51
+
52
+ - [`BinarySemaphore`](BinarySemaphore.md)
53
+
37
54
  ## Constructors
38
55
 
39
56
  ### new Semaphore()
40
57
 
41
- > **new Semaphore**(`maxConcurrency`, `__namedParameters`): [`Semaphore`](Semaphore.md)
58
+ > **new Semaphore**(`maxConcurrency`, `options`?): [`Semaphore`](Semaphore.md)
59
+
60
+ Defined in: [packages/ai-tool/src/utils/async-semaphore.ts:390](https://github.com/isdk/ai-tool.js/blob/6a89194ac34437a1bc58f7ec590cd22976939ca6/src/utils/async-semaphore.ts#L390)
42
61
 
43
62
  Creates a semaphore object. The first argument is the maximum concurrently number and the second argument is optional.
44
63
 
45
64
  #### Parameters
46
65
 
47
- **maxConcurrency**: `number`
66
+ ##### maxConcurrency
48
67
 
49
68
  The maximum number of callers allowed to acquire the semaphore concurrently.
50
69
 
51
- **\_\_namedParameters** = `{}`
70
+ `number` | [`SemaphoreOptions`](../interfaces/SemaphoreOptions.md)
52
71
 
53
- **\_\_namedParameters.capacity?**: `number` = `DefaultAsyncSemaphoreCapacity`
72
+ ##### options?
54
73
 
55
- • **\_\_namedParameters.initFn?** = `defaultInit`
56
-
57
- • **\_\_namedParameters.pauseFn?**
58
-
59
- • **\_\_namedParameters.resumeFn?**
74
+ [`SemaphoreOptions`](../interfaces/SemaphoreOptions.md)
60
75
 
61
76
  #### Returns
62
77
 
63
78
  [`Semaphore`](Semaphore.md)
64
79
 
65
- #### Defined in
80
+ #### Overrides
66
81
 
67
- [packages/ai-tool/src/utils/async-semaphore.ts:207](https://github.com/isdk/ai-tool.js/blob/b0813174e9b350ae47231f8e5f885150313123b0/src/utils/async-semaphore.ts#L207)
82
+ [`BinarySemaphore`](BinarySemaphore.md).[`constructor`](BinarySemaphore.md#constructors)
68
83
 
69
84
  ## Properties
70
85
 
86
+ ### \_activeCount
87
+
88
+ > `protected` **\_activeCount**: `number`
89
+
90
+ Defined in: [packages/ai-tool/src/utils/async-semaphore.ts:97](https://github.com/isdk/ai-tool.js/blob/6a89194ac34437a1bc58f7ec590cd22976939ca6/src/utils/async-semaphore.ts#L97)
91
+
92
+ #### Inherited from
93
+
94
+ [`BinarySemaphore`](BinarySemaphore.md).[`_activeCount`](BinarySemaphore.md#_activecount)
95
+
96
+ ***
97
+
98
+ ### emitter
99
+
100
+ > `protected` **emitter**: [`EventEmitter`](EventEmitter.md)
101
+
102
+ Defined in: [packages/ai-tool/src/utils/async-semaphore.ts:91](https://github.com/isdk/ai-tool.js/blob/6a89194ac34437a1bc58f7ec590cd22976939ca6/src/utils/async-semaphore.ts#L91)
103
+
104
+ #### Inherited from
105
+
106
+ [`BinarySemaphore`](BinarySemaphore.md).[`emitter`](BinarySemaphore.md#emitter)
107
+
108
+ ***
109
+
110
+ ### free
111
+
112
+ > `protected` **free**: `Deque`\<`any`\>
113
+
114
+ Defined in: [packages/ai-tool/src/utils/async-semaphore.ts:374](https://github.com/isdk/ai-tool.js/blob/6a89194ac34437a1bc58f7ec590cd22976939ca6/src/utils/async-semaphore.ts#L374)
115
+
116
+ #### Overrides
117
+
118
+ [`BinarySemaphore`](BinarySemaphore.md).[`free`](BinarySemaphore.md#free)
119
+
120
+ ***
121
+
122
+ ### initTokenFn()
123
+
124
+ > `protected` **initTokenFn**: (`token`?) => `void`
125
+
126
+ Defined in: [packages/ai-tool/src/utils/async-semaphore.ts:95](https://github.com/isdk/ai-tool.js/blob/6a89194ac34437a1bc58f7ec590cd22976939ca6/src/utils/async-semaphore.ts#L95)
127
+
128
+ #### Parameters
129
+
130
+ ##### token?
131
+
132
+ `any`
133
+
134
+ #### Returns
135
+
136
+ `void`
137
+
138
+ #### Inherited from
139
+
140
+ [`BinarySemaphore`](BinarySemaphore.md).[`initTokenFn`](BinarySemaphore.md#inittokenfn)
141
+
142
+ ***
143
+
71
144
  ### maxConcurrency
72
145
 
73
146
  > `readonly` **maxConcurrency**: `number`
74
147
 
75
- #### Defined in
148
+ Defined in: [packages/ai-tool/src/utils/async-semaphore.ts:373](https://github.com/isdk/ai-tool.js/blob/6a89194ac34437a1bc58f7ec590cd22976939ca6/src/utils/async-semaphore.ts#L373)
149
+
150
+ ***
151
+
152
+ ### paused
153
+
154
+ > `protected` **paused**: `boolean`
155
+
156
+ Defined in: [packages/ai-tool/src/utils/async-semaphore.ts:96](https://github.com/isdk/ai-tool.js/blob/6a89194ac34437a1bc58f7ec590cd22976939ca6/src/utils/async-semaphore.ts#L96)
157
+
158
+ #### Inherited from
159
+
160
+ [`BinarySemaphore`](BinarySemaphore.md).[`paused`](BinarySemaphore.md#paused)
161
+
162
+ ***
163
+
164
+ ### pauseFn()?
165
+
166
+ > `protected` `optional` **pauseFn**: () => `void`
167
+
168
+ Defined in: [packages/ai-tool/src/utils/async-semaphore.ts:93](https://github.com/isdk/ai-tool.js/blob/6a89194ac34437a1bc58f7ec590cd22976939ca6/src/utils/async-semaphore.ts#L93)
169
+
170
+ #### Returns
171
+
172
+ `void`
173
+
174
+ #### Inherited from
76
175
 
77
- [packages/ai-tool/src/utils/async-semaphore.ts:151](https://github.com/isdk/ai-tool.js/blob/b0813174e9b350ae47231f8e5f885150313123b0/src/utils/async-semaphore.ts#L151)
176
+ [`BinarySemaphore`](BinarySemaphore.md).[`pauseFn`](BinarySemaphore.md#pausefn)
177
+
178
+ ***
179
+
180
+ ### resumeFn()?
181
+
182
+ > `protected` `optional` **resumeFn**: () => `void`
183
+
184
+ Defined in: [packages/ai-tool/src/utils/async-semaphore.ts:94](https://github.com/isdk/ai-tool.js/blob/6a89194ac34437a1bc58f7ec590cd22976939ca6/src/utils/async-semaphore.ts#L94)
185
+
186
+ #### Returns
187
+
188
+ `void`
189
+
190
+ #### Inherited from
191
+
192
+ [`BinarySemaphore`](BinarySemaphore.md).[`resumeFn`](BinarySemaphore.md#resumefn)
193
+
194
+ ***
195
+
196
+ ### useDefaultTokens
197
+
198
+ > `protected` **useDefaultTokens**: `boolean`
199
+
200
+ Defined in: [packages/ai-tool/src/utils/async-semaphore.ts:92](https://github.com/isdk/ai-tool.js/blob/6a89194ac34437a1bc58f7ec590cd22976939ca6/src/utils/async-semaphore.ts#L92)
201
+
202
+ #### Inherited from
203
+
204
+ [`BinarySemaphore`](BinarySemaphore.md).[`useDefaultTokens`](BinarySemaphore.md#usedefaulttokens)
78
205
 
79
206
  ***
80
207
 
81
208
  ### waiting
82
209
 
83
- > `readonly` **waiting**: `Deque`
210
+ > `readonly` **waiting**: `Deque`\<`undefined` \| [`SemaphoreTaskItem`](../interfaces/SemaphoreTaskItem.md)\>
211
+
212
+ Defined in: [packages/ai-tool/src/utils/async-semaphore.ts:89](https://github.com/isdk/ai-tool.js/blob/6a89194ac34437a1bc58f7ec590cd22976939ca6/src/utils/async-semaphore.ts#L89)
213
+
214
+ #### Inherited from
215
+
216
+ [`BinarySemaphore`](BinarySemaphore.md).[`waiting`](BinarySemaphore.md#waiting)
217
+
218
+ ## Accessors
219
+
220
+ ### activeCount
221
+
222
+ #### Get Signature
223
+
224
+ > **get** **activeCount**(): `number`
225
+
226
+ Defined in: [packages/ai-tool/src/utils/async-semaphore.ts:318](https://github.com/isdk/ai-tool.js/blob/6a89194ac34437a1bc58f7ec590cd22976939ca6/src/utils/async-semaphore.ts#L318)
227
+
228
+ Get the total count of all active operations.
84
229
 
85
- #### Defined in
230
+ This method returns the number of operations that are either:
231
+ - Waiting in the queue to acquire the semaphore (`pendingCount`).
232
+ - Already acquired the semaphore but have not yet released it.
86
233
 
87
- [packages/ai-tool/src/utils/async-semaphore.ts:152](https://github.com/isdk/ai-tool.js/blob/b0813174e9b350ae47231f8e5f885150313123b0/src/utils/async-semaphore.ts#L152)
234
+ ##### Returns
235
+
236
+ `number`
237
+
238
+ The total count of active operations, including both waiting and ongoing tasks.
239
+
240
+ #### Inherited from
241
+
242
+ [`BinarySemaphore`](BinarySemaphore.md).[`activeCount`](BinarySemaphore.md#activecount)
243
+
244
+ ***
245
+
246
+ ### pendingCount
247
+
248
+ #### Get Signature
249
+
250
+ > **get** **pendingCount**(): `number`
251
+
252
+ Defined in: [packages/ai-tool/src/utils/async-semaphore.ts:327](https://github.com/isdk/ai-tool.js/blob/6a89194ac34437a1bc58f7ec590cd22976939ca6/src/utils/async-semaphore.ts#L327)
253
+
254
+ Get the number of callers waiting on the semaphore, i.e. the number of pending promises.
255
+
256
+ ##### Returns
257
+
258
+ `number`
259
+
260
+ The number of waiters in the waiting list.
261
+
262
+ #### Inherited from
263
+
264
+ [`BinarySemaphore`](BinarySemaphore.md).[`pendingCount`](BinarySemaphore.md#pendingcount)
88
265
 
89
266
  ## Methods
90
267
 
268
+ ### \_dispatchTask()
269
+
270
+ > **\_dispatchTask**(`task`, `options`?): `void`
271
+
272
+ Defined in: [packages/ai-tool/src/utils/async-semaphore.ts:212](https://github.com/isdk/ai-tool.js/blob/6a89194ac34437a1bc58f7ec590cd22976939ca6/src/utils/async-semaphore.ts#L212)
273
+
274
+ #### Parameters
275
+
276
+ ##### task
277
+
278
+ [`SemaphoreTaskItem`](../interfaces/SemaphoreTaskItem.md)
279
+
280
+ ##### options?
281
+
282
+ [`BinarySemaphoreReleaseOptions`](../interfaces/BinarySemaphoreReleaseOptions.md)
283
+
284
+ #### Returns
285
+
286
+ `void`
287
+
288
+ #### Inherited from
289
+
290
+ [`BinarySemaphore`](BinarySemaphore.md).[`_dispatchTask`](BinarySemaphore.md#_dispatchtask)
291
+
292
+ ***
293
+
294
+ ### \_newReleaser()
295
+
296
+ > **\_newReleaser**(`options`?): [`BinarySemaphoreReleaserFunc`](../interfaces/BinarySemaphoreReleaserFunc.md)
297
+
298
+ Defined in: [packages/ai-tool/src/utils/async-semaphore.ts:199](https://github.com/isdk/ai-tool.js/blob/6a89194ac34437a1bc58f7ec590cd22976939ca6/src/utils/async-semaphore.ts#L199)
299
+
300
+ #### Parameters
301
+
302
+ ##### options?
303
+
304
+ [`BinarySemaphoreReleaseOptions`](../interfaces/BinarySemaphoreReleaseOptions.md)
305
+
306
+ #### Returns
307
+
308
+ [`BinarySemaphoreReleaserFunc`](../interfaces/BinarySemaphoreReleaserFunc.md)
309
+
310
+ #### Inherited from
311
+
312
+ [`BinarySemaphore`](BinarySemaphore.md).[`_newReleaser`](BinarySemaphore.md#_newreleaser)
313
+
314
+ ***
315
+
316
+ ### abort()
317
+
318
+ > **abort**(`reason`?): `void`
319
+
320
+ Defined in: [packages/ai-tool/src/utils/async-semaphore.ts:301](https://github.com/isdk/ai-tool.js/blob/6a89194ac34437a1bc58f7ec590cd22976939ca6/src/utils/async-semaphore.ts#L301)
321
+
322
+ #### Parameters
323
+
324
+ ##### reason?
325
+
326
+ `any`
327
+
328
+ #### Returns
329
+
330
+ `void`
331
+
332
+ #### Inherited from
333
+
334
+ [`BinarySemaphore`](BinarySemaphore.md).[`abort`](BinarySemaphore.md#abort)
335
+
336
+ ***
337
+
91
338
  ### acquire()
92
339
 
93
- > **acquire**(`signal`?): `Promise`\<`any`\>
340
+ > **acquire**(`options`?): `Promise`\<[`BinarySemaphoreReleaserFunc`](../interfaces/BinarySemaphoreReleaserFunc.md)\>
341
+
342
+ Defined in: [packages/ai-tool/src/utils/async-semaphore.ts:243](https://github.com/isdk/ai-tool.js/blob/6a89194ac34437a1bc58f7ec590cd22976939ca6/src/utils/async-semaphore.ts#L243)
94
343
 
95
344
  Acquire a token from the semaphore, thus decrement the number of available execution slots. If initFn is not used then the return value of the function can be discarded.
96
345
 
97
346
  #### Parameters
98
347
 
99
- **signal?**: `AbortSignal`
348
+ ##### options?
349
+
350
+ [`BinarySemaphoreAcquireOptions`](../interfaces/BinarySemaphoreAcquireOptions.md)
100
351
 
101
352
  #### Returns
102
353
 
103
- `Promise`\<`any`\>
354
+ `Promise`\<[`BinarySemaphoreReleaserFunc`](../interfaces/BinarySemaphoreReleaserFunc.md)\>
104
355
 
105
- #### Defined in
356
+ A promise that resolves to a release function when a token is acquired. If the semaphore is full, the caller will be added to a waiting queue.
106
357
 
107
- [packages/ai-tool/src/utils/async-semaphore.ts:265](https://github.com/isdk/ai-tool.js/blob/b0813174e9b350ae47231f8e5f885150313123b0/src/utils/async-semaphore.ts#L265)
358
+ #### Inherited from
359
+
360
+ [`BinarySemaphore`](BinarySemaphore.md).[`acquire`](BinarySemaphore.md#acquire)
108
361
 
109
362
  ***
110
363
 
@@ -112,66 +365,174 @@ Acquire a token from the semaphore, thus decrement the number of available execu
112
365
 
113
366
  > **drain**(): `Promise`\<`any`[]\>
114
367
 
368
+ Defined in: [packages/ai-tool/src/utils/async-semaphore.ts:439](https://github.com/isdk/ai-tool.js/blob/6a89194ac34437a1bc58f7ec590cd22976939ca6/src/utils/async-semaphore.ts#L439)
369
+
115
370
  Drains the semaphore and returns all the initialized tokens in an array. Draining is an ideal way to ensure there are no pending async tasks, for example before a process will terminate.
116
371
 
117
372
  #### Returns
118
373
 
119
374
  `Promise`\<`any`[]\>
120
375
 
121
- #### Defined in
376
+ #### Overrides
122
377
 
123
- [packages/ai-tool/src/utils/async-semaphore.ts:301](https://github.com/isdk/ai-tool.js/blob/b0813174e9b350ae47231f8e5f885150313123b0/src/utils/async-semaphore.ts#L301)
378
+ [`BinarySemaphore`](BinarySemaphore.md).[`drain`](BinarySemaphore.md#drain)
124
379
 
125
380
  ***
126
381
 
127
- ### pendingCount()
382
+ ### init()
128
383
 
129
- > **pendingCount**(): `number`
384
+ > **init**(`options`): `void`
385
+
386
+ Defined in: [packages/ai-tool/src/utils/async-semaphore.ts:193](https://github.com/isdk/ai-tool.js/blob/6a89194ac34437a1bc58f7ec590cd22976939ca6/src/utils/async-semaphore.ts#L193)
387
+
388
+ #### Parameters
130
389
 
131
- Returns the number of callers waiting on the semaphore, i.e. the number of pending promises.
390
+ ##### options
391
+
392
+ [`BinarySemaphoreOptions`](../interfaces/BinarySemaphoreOptions.md)
132
393
 
133
394
  #### Returns
134
395
 
135
- `number`
396
+ `void`
136
397
 
137
- The number of waiters in the waiting list.
398
+ #### Inherited from
399
+
400
+ [`BinarySemaphore`](BinarySemaphore.md).[`init`](BinarySemaphore.md#init)
401
+
402
+ ***
403
+
404
+ ### initFree()
405
+
406
+ > **initFree**(`options`): `void`
407
+
408
+ Defined in: [packages/ai-tool/src/utils/async-semaphore.ts:408](https://github.com/isdk/ai-tool.js/blob/6a89194ac34437a1bc58f7ec590cd22976939ca6/src/utils/async-semaphore.ts#L408)
409
+
410
+ #### Parameters
411
+
412
+ ##### options
413
+
414
+ [`SemaphoreOptions`](../interfaces/SemaphoreOptions.md)
138
415
 
139
- #### Defined in
416
+ #### Returns
417
+
418
+ `void`
419
+
420
+ #### Overrides
421
+
422
+ [`BinarySemaphore`](BinarySemaphore.md).[`initFree`](BinarySemaphore.md#initfree)
423
+
424
+ ***
425
+
426
+ ### lock()
427
+
428
+ > **lock**(`options`?): `any`
429
+
430
+ Defined in: [packages/ai-tool/src/utils/async-semaphore.ts:435](https://github.com/isdk/ai-tool.js/blob/6a89194ac34437a1bc58f7ec590cd22976939ca6/src/utils/async-semaphore.ts#L435)
431
+
432
+ #### Parameters
433
+
434
+ ##### options?
435
+
436
+ [`BinarySemaphoreAcquireOptions`](../interfaces/BinarySemaphoreAcquireOptions.md)
437
+
438
+ #### Returns
439
+
440
+ `any`
441
+
442
+ #### Overrides
443
+
444
+ [`BinarySemaphore`](BinarySemaphore.md).[`lock`](BinarySemaphore.md#lock)
445
+
446
+ ***
447
+
448
+ ### onReleased()
449
+
450
+ > **onReleased**(`options`?): `void`
451
+
452
+ Defined in: [packages/ai-tool/src/utils/async-semaphore.ts:177](https://github.com/isdk/ai-tool.js/blob/6a89194ac34437a1bc58f7ec590cd22976939ca6/src/utils/async-semaphore.ts#L177)
453
+
454
+ #### Parameters
455
+
456
+ ##### options?
457
+
458
+ [`BinarySemaphoreReleaseOptions`](../interfaces/BinarySemaphoreReleaseOptions.md)
140
459
 
141
- [packages/ai-tool/src/utils/async-semaphore.ts:314](https://github.com/isdk/ai-tool.js/blob/b0813174e9b350ae47231f8e5f885150313123b0/src/utils/async-semaphore.ts#L314)
460
+ #### Returns
461
+
462
+ `void`
463
+
464
+ #### Inherited from
465
+
466
+ [`BinarySemaphore`](BinarySemaphore.md).[`onReleased`](BinarySemaphore.md#onreleased)
142
467
 
143
468
  ***
144
469
 
145
470
  ### release()
146
471
 
147
- > **release**(`token`?): `void`
472
+ > **release**(`options`?): `void`
473
+
474
+ Defined in: [packages/ai-tool/src/utils/async-semaphore.ts:288](https://github.com/isdk/ai-tool.js/blob/6a89194ac34437a1bc58f7ec590cd22976939ca6/src/utils/async-semaphore.ts#L288)
148
475
 
149
- Release the semaphore, thus increment the number of free execution slots. If initFn is used then the token returned by acquire() should be given as an argument when calling this function.
476
+ Releases the semaphore, incrementing the number of free execution slots. If there are tasks in the waiting queue, the next task will be dispatched.
150
477
 
151
478
  #### Parameters
152
479
 
153
- **token?**: `any`
480
+ ##### options?
481
+
482
+ [`BinarySemaphoreReleaseOptions`](../interfaces/BinarySemaphoreReleaseOptions.md)
154
483
 
155
484
  #### Returns
156
485
 
157
486
  `void`
158
487
 
159
- #### Defined in
488
+ #### Inherited from
160
489
 
161
- [packages/ai-tool/src/utils/async-semaphore.ts:294](https://github.com/isdk/ai-tool.js/blob/b0813174e9b350ae47231f8e5f885150313123b0/src/utils/async-semaphore.ts#L294)
490
+ [`BinarySemaphore`](BinarySemaphore.md).[`release`](BinarySemaphore.md#release)
162
491
 
163
492
  ***
164
493
 
165
494
  ### tryAcquire()
166
495
 
167
- > **tryAcquire**(): `any`
496
+ > **tryAcquire**(`options`?): `any`
497
+
498
+ Defined in: [packages/ai-tool/src/utils/async-semaphore.ts:416](https://github.com/isdk/ai-tool.js/blob/6a89194ac34437a1bc58f7ec590cd22976939ca6/src/utils/async-semaphore.ts#L416)
168
499
 
169
500
  Attempt to acquire a token from the semaphore, if one is available immediately. Otherwise, return undefined.
170
501
 
502
+ #### Parameters
503
+
504
+ ##### options?
505
+
506
+ [`BinarySemaphoreAcquireOptions`](../interfaces/BinarySemaphoreAcquireOptions.md)
507
+
171
508
  #### Returns
172
509
 
173
510
  `any`
174
511
 
175
- #### Defined in
512
+ Returns a token if the semaphore is not full; otherwise, returns `undefined`.
513
+
514
+ #### Overrides
515
+
516
+ [`BinarySemaphore`](BinarySemaphore.md).[`tryAcquire`](BinarySemaphore.md#tryacquire)
517
+
518
+ ***
519
+
520
+ ### unlock()
521
+
522
+ > **unlock**(`token`?): `void`
523
+
524
+ Defined in: [packages/ai-tool/src/utils/async-semaphore.ts:431](https://github.com/isdk/ai-tool.js/blob/6a89194ac34437a1bc58f7ec590cd22976939ca6/src/utils/async-semaphore.ts#L431)
525
+
526
+ #### Parameters
527
+
528
+ ##### token?
529
+
530
+ `any`
531
+
532
+ #### Returns
533
+
534
+ `void`
535
+
536
+ #### Overrides
176
537
 
177
- [packages/ai-tool/src/utils/async-semaphore.ts:258](https://github.com/isdk/ai-tool.js/blob/b0813174e9b350ae47231f8e5f885150313123b0/src/utils/async-semaphore.ts#L258)
538
+ [`BinarySemaphore`](BinarySemaphore.md).[`unlock`](BinarySemaphore.md#unlock)