@isdk/ai-tool 0.8.2 → 0.9.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 (405) hide show
  1. package/dist/chunk-BIJ2JH4U.mjs +1 -0
  2. package/dist/chunk-OYMVHUDZ.mjs +1 -0
  3. package/dist/funcs.d.mts +16 -5
  4. package/dist/funcs.d.ts +16 -5
  5. package/dist/funcs.js +1 -1
  6. package/dist/funcs.mjs +1 -1
  7. package/dist/index.d.mts +839 -563
  8. package/dist/index.d.ts +839 -563
  9. package/dist/index.js +1 -1
  10. package/dist/index.mjs +1 -1
  11. package/dist/test/util.d.mts +1 -1
  12. package/dist/test/util.d.ts +1 -1
  13. package/dist/test/util.js +1 -1
  14. package/dist/test/util.mjs +1 -1
  15. package/docs/api/@isdk/namespaces/ClientTools/README.md +11 -0
  16. package/docs/api/@isdk/namespaces/ClientTools/functions/get.md +27 -0
  17. package/docs/api/@isdk/namespaces/EventStates/variables/ABORT.md +1 -1
  18. package/docs/api/@isdk/namespaces/EventStates/variables/CONTINUE.md +1 -1
  19. package/docs/api/@isdk/namespaces/EventStates/variables/DONE.md +1 -1
  20. package/docs/api/@isdk/namespaces/EventStates/variables/STOPPED.md +1 -1
  21. package/docs/api/classes/BinarySemaphore.md +148 -67
  22. package/docs/api/classes/CancelableAbility.md +95 -43
  23. package/docs/api/classes/ClientToolTransport.md +31 -16
  24. package/docs/api/classes/ClientTools.md +868 -158
  25. package/docs/api/classes/CmdArgLexer.md +82 -0
  26. package/docs/api/classes/CmdArgParser.md +56 -0
  27. package/docs/api/classes/ConfigFile.md +6 -6
  28. package/docs/api/classes/EnvPromptTemplate.md +224 -52
  29. package/docs/api/classes/EventClient.md +902 -192
  30. package/docs/api/classes/EventEmitter.md +62 -12
  31. package/docs/api/classes/EventServer.md +895 -182
  32. package/docs/api/classes/EventToolFunc.md +801 -123
  33. package/docs/api/classes/FStringPromptTemplate.md +224 -52
  34. package/docs/api/classes/FewShotPromptTemplate.md +231 -59
  35. package/docs/api/classes/GolangPromptTemplate.md +224 -52
  36. package/docs/api/classes/HttpClientToolTransport.md +33 -19
  37. package/docs/api/classes/HttpServerToolTransport.md +15 -15
  38. package/docs/api/classes/IntSet.md +21 -21
  39. package/docs/api/classes/MailboxClientTransport.md +398 -0
  40. package/docs/api/classes/MailboxServerTransport.md +433 -0
  41. package/docs/api/classes/PromptExampleSelector.md +11 -11
  42. package/docs/api/classes/PromptTemplate.md +199 -51
  43. package/docs/api/classes/ReadableStreamError.md +2 -2
  44. package/docs/api/classes/ResClientTools.md +875 -165
  45. package/docs/api/classes/ResServerTools.md +869 -156
  46. package/docs/api/classes/RpcMethodsClientTool.md +870 -160
  47. package/docs/api/classes/RpcMethodsServerTool.md +865 -152
  48. package/docs/api/classes/SSEChannel.md +23 -23
  49. package/docs/api/classes/Semaphore.md +148 -76
  50. package/docs/api/classes/ServerToolTransport.md +14 -13
  51. package/docs/api/classes/ServerTools.md +854 -138
  52. package/docs/api/classes/SignalGate.md +12 -12
  53. package/docs/api/classes/SseClientPubSubTransport.md +4 -4
  54. package/docs/api/classes/SseServerPubSubTransport.md +13 -13
  55. package/docs/api/classes/TaskAbortController.md +33 -11
  56. package/docs/api/classes/ToolFunc.md +725 -119
  57. package/docs/api/classes/ToolTransport.md +7 -7
  58. package/docs/api/classes/YamlTypeBaseObject.md +2 -2
  59. package/docs/api/enumerations/AsyncFeatureBits.md +4 -4
  60. package/docs/api/enumerations/AsyncFeatures.md +4 -4
  61. package/docs/api/enumerations/CmdArgTokenType.md +129 -0
  62. package/docs/api/enumerations/HashAlgorithm.md +38 -12
  63. package/docs/api/functions/AIArgProcessor.md +8 -17
  64. package/docs/api/functions/AIStream.md +1 -1
  65. package/docs/api/functions/ChoiceArgProcessor.md +13 -15
  66. package/docs/api/functions/DefaultDateFormat.md +1 -1
  67. package/docs/api/functions/ObjectArgsToArgsInfo.md +11 -9
  68. package/docs/api/functions/RateLimit.md +33 -6
  69. package/docs/api/functions/TemplateArgProcessor.md +13 -15
  70. package/docs/api/functions/assignDirs.md +1 -1
  71. package/docs/api/functions/beforeShutdown.md +3 -3
  72. package/docs/api/functions/calcPerplexity.md +3 -3
  73. package/docs/api/functions/calcPerplexitySimple.md +3 -3
  74. package/docs/api/functions/cmdArgEvaluate.md +28 -0
  75. package/docs/api/functions/cmdArgsToMergedObject.md +34 -0
  76. package/docs/api/functions/completeSentences.md +1 -1
  77. package/docs/api/functions/concatText.md +1 -1
  78. package/docs/api/functions/countLLMTokens.md +1 -1
  79. package/docs/api/functions/countRegexMatches.md +1 -1
  80. package/docs/api/functions/createCallbacksTransformer.md +23 -19
  81. package/docs/api/functions/createEmptyReadableStream.md +1 -1
  82. package/docs/api/functions/createEndWithRepetitionDetector.md +4 -4
  83. package/docs/api/functions/createEventStreamTransformer.md +1 -1
  84. package/docs/api/functions/createHfValueFunc.md +1 -1
  85. package/docs/api/functions/createLRUCache.md +1 -1
  86. package/docs/api/functions/createYamlObjectTag.md +1 -1
  87. package/docs/api/functions/dateToText.md +1 -1
  88. package/docs/api/functions/decodeCharset.md +1 -1
  89. package/docs/api/functions/defaultsWithConcat.md +1 -1
  90. package/docs/api/functions/detectCharset.md +1 -1
  91. package/docs/api/functions/encodeLLMTokens.md +1 -1
  92. package/docs/api/functions/ensureQuoted.md +3 -1
  93. package/docs/api/functions/evaluateExpression.md +40 -0
  94. package/docs/api/functions/eventable.md +1 -1
  95. package/docs/api/functions/expandConfig.md +1 -1
  96. package/docs/api/functions/expandEnv.md +1 -1
  97. package/docs/api/functions/expandObjEnv.md +1 -1
  98. package/docs/api/functions/expandPath.md +1 -1
  99. package/docs/api/functions/expandPathInObject.md +1 -1
  100. package/docs/api/functions/expandPaths.md +1 -1
  101. package/docs/api/functions/extNameLevel.md +1 -1
  102. package/docs/api/functions/extractCodeBlock.md +51 -0
  103. package/docs/api/functions/fileIsExists.md +3 -3
  104. package/docs/api/functions/filterValidFnScope.md +3 -3
  105. package/docs/api/functions/findIndexNonEmptyFrom.md +1 -1
  106. package/docs/api/functions/findPort.md +13 -5
  107. package/docs/api/functions/formatTextWithSpace.md +1 -1
  108. package/docs/api/functions/funcGetMeta.md +1 -1
  109. package/docs/api/functions/funcWithMeta.md +4 -4
  110. package/docs/api/functions/genUrlParamsStr.md +1 -1
  111. package/docs/api/functions/getAllEnumKeys.md +1 -1
  112. package/docs/api/functions/getConfigFileNames.md +1 -1
  113. package/docs/api/functions/getConfigs.md +1 -1
  114. package/docs/api/functions/getEnvVairables.md +1 -1
  115. package/docs/api/functions/getFileMetaInfo.md +1 -1
  116. package/docs/api/functions/getHashAlgoBySize.md +1 -1
  117. package/docs/api/functions/getKeysPath.md +1 -1
  118. package/docs/api/functions/getLLMTokenizer.md +1 -1
  119. package/docs/api/functions/getMultiLevelExtname.md +1 -1
  120. package/docs/api/functions/getPackageDir.md +1 -1
  121. package/docs/api/functions/getRealFilepath.md +1 -1
  122. package/docs/api/functions/getResponseErrorReadableStream.md +2 -2
  123. package/docs/api/functions/getXDGConfigs.md +1 -1
  124. package/docs/api/functions/hasDirectoryIn.md +3 -3
  125. package/docs/api/functions/hash.md +25 -4
  126. package/docs/api/functions/hashFile.md +1 -1
  127. package/docs/api/functions/hashObject.md +23 -1
  128. package/docs/api/functions/hashStream.md +25 -4
  129. package/docs/api/functions/initShutdown.md +1 -1
  130. package/docs/api/functions/isIdentifier.md +30 -0
  131. package/docs/api/functions/isLangUsingSpaces.md +1 -1
  132. package/docs/api/functions/isListItemString.md +3 -3
  133. package/docs/api/functions/isModelNameMatched.md +3 -3
  134. package/docs/api/functions/isPathIdentifier.md +23 -0
  135. package/docs/api/functions/isPunctuationChar.md +1 -1
  136. package/docs/api/functions/isQuoted.md +4 -1
  137. package/docs/api/functions/isRegExp.md +20 -1
  138. package/docs/api/functions/isSameString.md +1 -1
  139. package/docs/api/functions/isSectionString.md +3 -3
  140. package/docs/api/functions/isSentenceEnding.md +1 -1
  141. package/docs/api/functions/isSepLineString.md +3 -3
  142. package/docs/api/functions/isStrWrapped.md +3 -1
  143. package/docs/api/functions/isSubdirectory.md +1 -1
  144. package/docs/api/functions/isTitleString.md +3 -3
  145. package/docs/api/functions/isValidFilename.md +1 -1
  146. package/docs/api/functions/isValidFilepath.md +1 -1
  147. package/docs/api/functions/isWebStream.md +1 -1
  148. package/docs/api/functions/joinSplitWords.md +1 -1
  149. package/docs/api/functions/jsonFilterToWhere.md +1 -1
  150. package/docs/api/functions/jsonToMarkdownStr.md +1 -1
  151. package/docs/api/functions/loadAIConfig.md +1 -1
  152. package/docs/api/functions/loadConfig.md +1 -1
  153. package/docs/api/functions/loadConfigFile.md +1 -1
  154. package/docs/api/functions/loadFileFromPaths.md +1 -1
  155. package/docs/api/functions/loadTextFromPaths.md +1 -1
  156. package/docs/api/functions/lrucache.md +1 -1
  157. package/docs/api/functions/matchUrlProtocol.md +3 -3
  158. package/docs/api/functions/memoize.md +1 -1
  159. package/docs/api/functions/mergeArray.md +1 -1
  160. package/docs/api/functions/messagesToText.md +1 -1
  161. package/docs/api/functions/normalizePath.md +1 -1
  162. package/docs/api/functions/paramsSizeToScaleStr.md +1 -1
  163. package/docs/api/functions/parseCommand.md +21 -4
  164. package/docs/api/functions/parseJsJson.md +1 -1
  165. package/docs/api/functions/parseJsJsonSimpleSync.md +1 -1
  166. package/docs/api/functions/parseObjectArguments.md +17 -33
  167. package/docs/api/functions/parseYaml.md +1 -1
  168. package/docs/api/functions/prependNewlineIfMultiline.md +39 -0
  169. package/docs/api/functions/pruneSubdirectories.md +1 -1
  170. package/docs/api/functions/pruneSubdirectoriesInPlace.md +1 -1
  171. package/docs/api/functions/quoteStr.md +4 -1
  172. package/docs/api/functions/readFilenamesRecursiveSync.md +1 -1
  173. package/docs/api/functions/readTextFileChunks.md +1 -1
  174. package/docs/api/functions/readTextFileChunksEx.md +1 -1
  175. package/docs/api/functions/readableFromAsyncIterable.md +1 -1
  176. package/docs/api/functions/registerCoreTools.md +1 -1
  177. package/docs/api/functions/registerYamlTag.md +2 -2
  178. package/docs/api/functions/removeMarkdownBold.md +1 -1
  179. package/docs/api/functions/removeMarkdownBoldAndItalic.md +1 -1
  180. package/docs/api/functions/removeMarkdownItalic.md +1 -1
  181. package/docs/api/functions/replaceWithPlaceholder.md +3 -18
  182. package/docs/api/functions/restoreFromPlacehoders.md +2 -20
  183. package/docs/api/functions/sanitizeFilename.md +1 -1
  184. package/docs/api/functions/sanitizeFilepath.md +1 -1
  185. package/docs/api/functions/saveConfigFile.md +1 -1
  186. package/docs/api/functions/scaleStrToParamsSize.md +1 -1
  187. package/docs/api/functions/shutdown.md +2 -2
  188. package/docs/api/functions/simplifyObjectArguments.md +4 -1
  189. package/docs/api/functions/simplifyResult.md +34 -0
  190. package/docs/api/functions/sleep.md +1 -1
  191. package/docs/api/functions/sortedValues.md +1 -1
  192. package/docs/api/functions/splitChunks.md +1 -1
  193. package/docs/api/functions/splitParagraph.md +1 -1
  194. package/docs/api/functions/splitSentence.md +1 -1
  195. package/docs/api/functions/splitWords.md +1 -1
  196. package/docs/api/functions/stringifyYaml.md +1 -1
  197. package/docs/api/functions/stripConsoleColor.md +1 -1
  198. package/docs/api/functions/textToDate.md +1 -1
  199. package/docs/api/functions/textify.md +43 -0
  200. package/docs/api/functions/toDateTime.md +3 -3
  201. package/docs/api/functions/toRegExp.md +1 -1
  202. package/docs/api/functions/trimStartOfStreamHelper.md +1 -1
  203. package/docs/api/functions/truncTo.md +1 -1
  204. package/docs/api/functions/truncateByToken.md +1 -1
  205. package/docs/api/functions/truncateToTokenLimit.md +1 -1
  206. package/docs/api/functions/truncateToTokenLimitEx.md +1 -1
  207. package/docs/api/functions/uuid.md +1 -1
  208. package/docs/api/functions/wrapEventEmitter.md +1 -1
  209. package/docs/api/functions/wrapFlagValue.md +29 -0
  210. package/docs/api/functions/xxhash.md +27 -6
  211. package/docs/api/functions/xxhash32.md +22 -4
  212. package/docs/api/functions/xxhash64.md +22 -4
  213. package/docs/api/functions/xxhashAsStr.md +27 -6
  214. package/docs/api/functions/yieldExec.md +1 -1
  215. package/docs/api/globals.md +51 -18
  216. package/docs/api/interfaces/AIChatAssistantMessageParam.md +14 -14
  217. package/docs/api/interfaces/AIChatContentPartBase.md +26 -0
  218. package/docs/api/interfaces/AIChatContentPartImage.md +15 -3
  219. package/docs/api/interfaces/AIChatContentPartText.md +15 -3
  220. package/docs/api/interfaces/AIChatMessageParamBase.md +9 -9
  221. package/docs/api/interfaces/AIChatMessageToolCall.md +12 -8
  222. package/docs/api/interfaces/AIChatSystemMessageParam.md +10 -10
  223. package/docs/api/interfaces/AIChatToolChoiceFuncObject.md +3 -3
  224. package/docs/api/interfaces/AIChatToolChoiceObject.md +2 -2
  225. package/docs/api/interfaces/AIChatToolDefinition.md +45 -0
  226. package/docs/api/interfaces/AIChatToolFunc.md +5 -5
  227. package/docs/api/interfaces/AIChatToolFuncParam.md +3 -3
  228. package/docs/api/interfaces/AIChatToolMessageParam.md +13 -13
  229. package/docs/api/interfaces/AIChatToolParam.md +2 -2
  230. package/docs/api/interfaces/AIChatToolTypeObject.md +2 -2
  231. package/docs/api/interfaces/AIChatUserMessageParam.md +14 -14
  232. package/docs/api/interfaces/AIResult.md +7 -7
  233. package/docs/api/interfaces/AIStreamParser.md +2 -2
  234. package/docs/api/interfaces/AIStreamParserOptions.md +2 -2
  235. package/docs/api/interfaces/BaseFunc.md +15 -15
  236. package/docs/api/interfaces/BaseFuncItem.md +16 -16
  237. package/docs/api/interfaces/BinarySemaphoreAcquireOptions.md +9 -2
  238. package/docs/api/interfaces/BinarySemaphoreOptions.md +22 -5
  239. package/docs/api/interfaces/BinarySemaphoreReleaseOptions.md +7 -5
  240. package/docs/api/interfaces/CancelableAbilityOptions.md +4 -4
  241. package/docs/api/interfaces/ClientFuncItem.md +70 -19
  242. package/docs/api/interfaces/CmdArgAIChoiceConfig.md +97 -0
  243. package/docs/api/interfaces/CmdArgArgsInfo.md +31 -0
  244. package/docs/api/interfaces/CmdArgContext.md +103 -0
  245. package/docs/api/interfaces/CmdArgFlagMetadata.md +21 -0
  246. package/docs/api/interfaces/CmdArgMapResult.md +41 -0
  247. package/docs/api/interfaces/CmdArgParseResult.md +51 -0
  248. package/docs/api/interfaces/CmdArgParsedCommand.md +41 -0
  249. package/docs/api/interfaces/CmdArgParserOptions.md +225 -0
  250. package/docs/api/interfaces/CmdArgProcessorResultOptions.md +22 -0
  251. package/docs/api/interfaces/CmdArgSimplifyOptions.md +101 -0
  252. package/docs/api/interfaces/CmdArgToken.md +51 -0
  253. package/docs/api/interfaces/EventClientFuncParams.md +5 -5
  254. package/docs/api/interfaces/EventServerFuncParams.md +21 -7
  255. package/docs/api/interfaces/FewShotPromptTemplateOptions.md +18 -6
  256. package/docs/api/interfaces/FuncItem.md +19 -15
  257. package/docs/api/interfaces/FuncParam.md +5 -5
  258. package/docs/api/interfaces/FuncParams.md +1 -1
  259. package/docs/api/interfaces/Funcs.md +1 -1
  260. package/docs/api/interfaces/HashAlgoParams.md +36 -5
  261. package/docs/api/interfaces/IClientToolTransport.md +24 -10
  262. package/docs/api/interfaces/IFileMetaInfo.md +8 -8
  263. package/docs/api/interfaces/IPubSubClientTransport.md +4 -4
  264. package/docs/api/interfaces/IPubSubServerTransport.md +14 -14
  265. package/docs/api/interfaces/IReadTextFileChunksOptions.md +11 -11
  266. package/docs/api/interfaces/IServerToolTransport.md +8 -8
  267. package/docs/api/interfaces/IToolTransport.md +5 -5
  268. package/docs/api/interfaces/ITruncateToTokenLimitOptions.md +10 -10
  269. package/docs/api/interfaces/JsonFilter.md +1 -1
  270. package/docs/api/interfaces/MailboxClientOptions.md +74 -0
  271. package/docs/api/interfaces/MailboxServerOptions.md +69 -0
  272. package/docs/api/interfaces/ProbabilityItem.md +4 -4
  273. package/docs/api/interfaces/PromptExampleSelectorOptions.md +3 -3
  274. package/docs/api/interfaces/PromptTemplateOptions.md +8 -0
  275. package/docs/api/interfaces/PubSubClientStream.md +11 -11
  276. package/docs/api/interfaces/PubSubServerSession.md +8 -8
  277. package/docs/api/interfaces/RegisterOptions.md +298 -0
  278. package/docs/api/interfaces/RemoteFuncItem.md +63 -20
  279. package/docs/api/interfaces/ReplacePlacehoderOptions.md +5 -5
  280. package/docs/api/interfaces/ResClientFuncParams.md +3 -3
  281. package/docs/api/interfaces/ResServerFuncParams.md +20 -6
  282. package/docs/api/interfaces/RpcMethodsClientFuncParams.md +2 -2
  283. package/docs/api/interfaces/RpcMethodsServerFuncParams.md +18 -4
  284. package/docs/api/interfaces/SanitizeFilenameOptions.md +3 -3
  285. package/docs/api/interfaces/SectionStringOptions.md +3 -3
  286. package/docs/api/interfaces/SemaphoreOptions.md +30 -7
  287. package/docs/api/interfaces/SemaphoreTaskItem.md +18 -5
  288. package/docs/api/interfaces/ServerFuncItem.md +71 -20
  289. package/docs/api/interfaces/ServerFuncParams.md +14 -4
  290. package/docs/api/interfaces/SplitSentenceOptions.md +5 -5
  291. package/docs/api/interfaces/StreamCallbacksAndOptions.md +80 -7
  292. package/docs/api/interfaces/TaskAbortControllers.md +2 -2
  293. package/docs/api/interfaces/TaskPromise.md +6 -6
  294. package/docs/api/interfaces/TextifyInlineOptions.md +51 -0
  295. package/docs/api/interfaces/TextifyOptions.md +108 -0
  296. package/docs/api/interfaces/ToolFuncContext.md +73 -0
  297. package/docs/api/interfaces/ToolFuncPackage.md +4 -4
  298. package/docs/api/interfaces/ToolFuncRegistryIsolateOptions.md +41 -0
  299. package/docs/api/interfaces/UnregisterOptions.md +56 -0
  300. package/docs/api/type-aliases/AIChatContentPart.md +2 -2
  301. package/docs/api/type-aliases/AIChatMessageParam.md +1 -1
  302. package/docs/api/type-aliases/AIChatRole.md +2 -2
  303. package/docs/api/type-aliases/AIChatTemplateCaps.md +239 -0
  304. package/docs/api/type-aliases/AIChatToolChoiceParam.md +1 -1
  305. package/docs/api/type-aliases/AIMessageType.md +1 -1
  306. package/docs/api/type-aliases/AIModelNameRule.md +1 -1
  307. package/docs/api/type-aliases/AIModelNameRuleFn.md +1 -1
  308. package/docs/api/type-aliases/AIModelNameRules.md +1 -1
  309. package/docs/api/type-aliases/AITextGenerationFinishReason.md +1 -1
  310. package/docs/api/type-aliases/ActionName.md +1 -1
  311. package/docs/api/type-aliases/ArgProcessor.md +24 -0
  312. package/docs/api/type-aliases/ArrayMergeWay.md +1 -1
  313. package/docs/api/type-aliases/AsyncTaskId.md +1 -1
  314. package/docs/api/type-aliases/BeforeShutdownListener.md +1 -1
  315. package/docs/api/type-aliases/CmdArgFlagValue.md +14 -0
  316. package/docs/api/type-aliases/CmdArgFlagsRecord.md +13 -0
  317. package/docs/api/type-aliases/EventErrorListenerFn.md +1 -1
  318. package/docs/api/type-aliases/EventListenerFn.md +1 -1
  319. package/docs/api/type-aliases/FuncParamType.md +1 -1
  320. package/docs/api/type-aliases/PromptExamples.md +1 -1
  321. package/docs/api/type-aliases/PubSubClientId.md +1 -1
  322. package/docs/api/type-aliases/PubSubCtx.md +6 -6
  323. package/docs/api/type-aliases/RpcMethodHandler.md +1 -1
  324. package/docs/api/type-aliases/SSEClient.md +5 -5
  325. package/docs/api/type-aliases/SemaphoreIsReadyFuncType.md +4 -1
  326. package/docs/api/type-aliases/SimplifiedResultType.md +14 -0
  327. package/docs/api/type-aliases/StreamCloseStatus.md +16 -0
  328. package/docs/api/type-aliases/TFunc.md +1 -1
  329. package/docs/api/type-aliases/TextifyInlineStyleMode.md +16 -0
  330. package/docs/api/type-aliases/TextifyStringQuoting.md +16 -0
  331. package/docs/api/type-aliases/UUIDVersions.md +3 -1
  332. package/docs/api/variables/AIChatRoles.md +2 -2
  333. package/docs/api/variables/AIMessageTypes.md +1 -1
  334. package/docs/api/variables/AITextGenerationFinishReasons.md +1 -1
  335. package/docs/api/variables/ActionNames.md +1 -1
  336. package/docs/api/variables/ArrayMergeWay.md +1 -1
  337. package/docs/api/variables/ArrayMergeWaySymbol.md +1 -1
  338. package/docs/api/variables/CMD_ARG_FLAG_SYMBOL.md +21 -0
  339. package/docs/api/variables/CMD_ARG_PROCESSOR_RESULT.md +22 -0
  340. package/docs/api/variables/CMD_ARG_UNRESOLVED_SYMBOL.md +16 -0
  341. package/docs/api/variables/ClientEventPrefix.md +2 -2
  342. package/docs/api/variables/ClientToolFuncSchema.md +27 -17
  343. package/docs/api/variables/DEFAULT_CONFIG_NAME.md +1 -1
  344. package/docs/api/variables/DefaultAsyncSemaphoreCapacity.md +4 -1
  345. package/docs/api/variables/EventBusName.md +2 -2
  346. package/docs/api/variables/EventName.md +2 -2
  347. package/docs/api/variables/FilenameReservedRegex.md +1 -1
  348. package/docs/api/variables/FuncMetaSymbol.md +2 -2
  349. package/docs/api/variables/IDENTIFIER_REGEX.md +14 -0
  350. package/docs/api/variables/LLM_TOKENIZER_NAMES.md +1 -1
  351. package/docs/api/variables/LLM_TOKENIZER_NAMES_MAP.md +1 -1
  352. package/docs/api/variables/PASSING_SCORE.md +1 -1
  353. package/docs/api/variables/PATH_IDENTIFIER_REGEX.md +13 -0
  354. package/docs/api/variables/RESERVED_WORDS.md +13 -0
  355. package/docs/api/variables/RStreamErrCode.md +1 -1
  356. package/docs/api/variables/RemoteToolFuncSchema.md +36 -4
  357. package/docs/api/variables/ResponseRStreamErrCode.md +1 -1
  358. package/docs/api/variables/RpcMethodsClientToolSchema.md +2 -2
  359. package/docs/api/variables/RpcMethodsServerToolSchema.md +2 -2
  360. package/docs/api/variables/SHUTDOWN_SIGNALS.md +1 -1
  361. package/docs/api/variables/SSEChannelAlreadyClosedErrCode.md +1 -1
  362. package/docs/api/variables/SecondaryCache.md +1 -1
  363. package/docs/api/variables/ServerToolFuncSchema.md +27 -17
  364. package/docs/api/variables/StrangeHumanName.md +1 -1
  365. package/docs/api/variables/ToolAsyncCancelableBit.md +1 -1
  366. package/docs/api/variables/ToolAsyncMultiTaskBit.md +1 -1
  367. package/docs/api/variables/ToolAsyncPriorityBit.md +1 -1
  368. package/docs/api/variables/ToolFuncSchema.md +13 -13
  369. package/docs/api/variables/WindowsReservedNameRegex.md +1 -1
  370. package/docs/api/variables/backendEventable.md +23 -3
  371. package/docs/api/variables/base32768.md +2 -2
  372. package/docs/api/variables/event.md +1 -1
  373. package/docs/api/variables/eventClient.md +1 -1
  374. package/docs/api/variables/eventServer.md +1 -1
  375. package/docs/api/variables/lrucache.md +1 -1
  376. package/docs/api/variables/makeToolFuncCancelable.md +23 -3
  377. package/docs/api/variables/wait.md +1 -1
  378. package/docs/transport.dev.md +206 -0
  379. package/package.json +12 -10
  380. package/dist/chunk-4FKBOPZI.mjs +0 -1
  381. package/dist/chunk-TGTHY57V.mjs +0 -1
  382. package/dist/find-port-qS1CZ9c-.d.mts +0 -3
  383. package/dist/find-port-qS1CZ9c-.d.ts +0 -3
  384. package/dist/index-BLW3R7VS.d.mts +0 -1826
  385. package/dist/index-BLW3R7VS.d.ts +0 -1826
  386. package/docs/api/@isdk/namespaces/uuidv5/README.md +0 -12
  387. package/docs/api/@isdk/namespaces/uuidv5/variables/DNS.md +0 -11
  388. package/docs/api/@isdk/namespaces/uuidv5/variables/URL.md +0 -11
  389. package/docs/api/functions/nanoid.md +0 -45
  390. package/docs/api/functions/parseObjectArgInfo.md +0 -33
  391. package/docs/api/functions/parseObjectArgumentInfos.md +0 -29
  392. package/docs/api/functions/parseObjectArgumentsAsArgInfos.md +0 -46
  393. package/docs/api/functions/uuidParse.md +0 -21
  394. package/docs/api/functions/uuidStringify.md +0 -25
  395. package/docs/api/functions/uuidValidate.md +0 -21
  396. package/docs/api/functions/uuidVersion.md +0 -21
  397. package/docs/api/functions/uuidv1.md +0 -61
  398. package/docs/api/functions/uuidv4.md +0 -61
  399. package/docs/api/functions/uuidv5.md +0 -69
  400. package/docs/api/functions/uuidv6.md +0 -61
  401. package/docs/api/functions/uuidv7.md +0 -61
  402. package/docs/api/interfaces/AIChoiceConfig.md +0 -65
  403. package/docs/api/interfaces/BinarySemaphoreReleaserFunc.md +0 -37
  404. package/docs/api/interfaces/ParseObjectArgumentOptions.md +0 -89
  405. package/docs/api/variables/uuidNIL.md +0 -11
@@ -1,1826 +0,0 @@
1
- import { EventEmitter, Event } from 'events-ex';
2
- import { AdvancePropertyManager } from 'property-manager';
3
- import { AbilityOptions } from 'custom-ability';
4
- import { CommonError } from '@isdk/common-error';
5
- import { Cache, ICacheOptions } from 'secondary-cache';
6
-
7
- /**
8
- * Represents the data type of a function parameter as a string (e.g., `'string'`, `'number'`).
9
- */
10
- type FuncParamType = string;
11
- /**
12
- * Describes a single function parameter, including its name, type, and description.
13
- * @interface
14
- */
15
- interface FuncParam {
16
- /**
17
- * The name of the parameter.
18
- * @type {string}
19
- */
20
- name?: string;
21
- /**
22
- * The data type of the parameter, represented as a string identifier (e.g., 'string', 'number').
23
- * @type {FuncParamType}
24
- */
25
- type?: FuncParamType;
26
- /**
27
- * Indicates whether the parameter is required.
28
- * @type {boolean}
29
- */
30
- required?: boolean;
31
- /**
32
- * A description of the parameter, explaining its purpose and usage.
33
- * @type {string}
34
- */
35
- description?: string;
36
- }
37
- /**
38
- * A map of function parameters, where each key is the parameter name.
39
- * The value can be either a detailed `FuncParam` object or a simple type string.
40
- *
41
- * @example
42
- * const params: FuncParams = {
43
- * userId: 'string',
44
- * profile: {
45
- * type: 'object',
46
- * description: 'User profile data'
47
- * }
48
- * };
49
- */
50
- interface FuncParams {
51
- [name: string]: FuncParam | FuncParamType;
52
- }
53
- /**
54
- * Defines the signature for a tool function's implementation.
55
- *
56
- * @param {ToolFunc} this - The `this` context is bound to the `ToolFunc` instance.
57
- * @param {...any[]} params - Variadic arguments passed to the function.
58
- * @returns {any} The result of the function's execution.
59
- */
60
- type TFunc = (this: ToolFunc, ...params: any[]) => any;
61
- /**
62
- * Base configuration for defining a tool function.
63
- * @interface
64
- */
65
- interface BaseFuncItem {
66
- /**
67
- * The unique name of the function.
68
- * @type {string}
69
- */
70
- name?: string;
71
- /**
72
- * Parameter definitions, which can be an object mapping names to definitions or an array for positional parameters.
73
- * @type {FuncParams | FuncParam[]}
74
- */
75
- params?: FuncParams | FuncParam[];
76
- /**
77
- * The expected return type of the function, described as a string or a JSON schema object.
78
- * @type {string | Record<string, any>}
79
- */
80
- result?: string | Record<string, any>;
81
- /**
82
- * The execution scope or context (`this`) for the function.
83
- * @type {any}
84
- */
85
- scope?: any;
86
- /**
87
- * Tags for grouping or filtering functions.
88
- * @type {string | string[]}
89
- */
90
- tags?: string | string[];
91
- /**
92
- * A lifecycle hook called once during the `ToolFunc` instance's initialization.
93
- * It allows for initial setup, state configuration, or property modification on the instance
94
- * before it is used or registered. The `this` context is the `ToolFunc` instance itself.
95
- *
96
- * @param {FuncItem} [options] - The configuration options for the function.
97
- * @example
98
- * const myFunc = new ToolFunc({
99
- * name: 'myFunc',
100
- * customState: 'initial',
101
- * setup() {
102
- * // `this` is the myFunc instance
103
- * this.customState = 'configured';
104
- * }
105
- * });
106
- * console.log(myFunc.customState); // Outputs: 'configured'
107
- */
108
- setup?: (this: ToolFunc, options?: FuncItem) => void;
109
- /**
110
- * If true, indicates that this function should be treated as a server-side API.
111
- * @type {boolean}
112
- */
113
- isApi?: boolean;
114
- /**
115
- * If true, indicates that the function has the *capability* to stream its output.
116
- * Whether a specific call is streamed is determined by a `stream` property in the runtime parameters.
117
- * @type {boolean}
118
- */
119
- stream?: boolean;
120
- /**
121
- * Optional aliases for the function name.
122
- * @type {string | string[]}
123
- */
124
- alias?: string | string[];
125
- /**
126
- * A bitmask representing asynchronous features supported by the function, built from `AsyncFeatureBits`.
127
- * This allows the system to understand if a function supports capabilities like cancellation or multi-tasking.
128
- * @see AsyncFeatureBits from `@src/utils/cancelable-ability.ts`
129
- * @type {number}
130
- * @example
131
- * import { AsyncFeatures } from './utils';
132
- * const func = new ToolFunc({
133
- * name: 'cancellableTask',
134
- * asyncFeatures: AsyncFeatures.Cancelable | AsyncFeatures.MultiTask,
135
- * // ...
136
- * });
137
- */
138
- asyncFeatures?: number;
139
- /**
140
- * A map of dependencies this function has on other tool functions.
141
- * Declaring dependencies ensures that they are automatically registered when this function is registered.
142
- * This is crucial for building modular functions that rely on each other without needing to manage registration order manually.
143
- *
144
- * @type {{ [name: string]: ToolFunc }}
145
- * @example
146
- * const helperFunc = new ToolFunc({ name: 'helper', func: () => 'world' });
147
- * const mainFunc = new ToolFunc({
148
- * name: 'main',
149
- * depends: {
150
- * helper: helperFunc,
151
- * },
152
- * func() {
153
- * // We can now safely run the dependency
154
- * const result = this.runSync('helper');
155
- * return `Hello, ${result}`;
156
- * }
157
- * });
158
- * // When mainFunc is registered, helperFunc will be registered automatically.
159
- * mainFunc.register();
160
- */
161
- depends?: {
162
- [name: string]: ToolFunc;
163
- };
164
- /**
165
- * A detailed description of what the function does.
166
- * @type {string}
167
- */
168
- description?: string;
169
- /**
170
- * A concise, human-readable title for the function, often used in UI or by AI.
171
- * @type {string}
172
- */
173
- title?: string;
174
- }
175
- /**
176
- * Extends `BaseFuncItem` to include the actual function implementation.
177
- * @interface
178
- */
179
- interface FuncItem extends BaseFuncItem {
180
- /**
181
- * The implementation of the tool function.
182
- * @type {TFunc}
183
- */
184
- func?: TFunc;
185
- }
186
- /**
187
- * Represents a fully-defined tool function where the implementation is mandatory.
188
- * @interface
189
- */
190
- interface BaseFunc extends BaseFuncItem {
191
- /**
192
- * The actual function implementation.
193
- * @param {...any} params - The parameters for the function.
194
- * @returns {any} The result of the function.
195
- */
196
- func(...params: any): any;
197
- }
198
- /**
199
- * A map of registered `ToolFunc` instances, indexed by their names.
200
- */
201
- interface Funcs {
202
- [name: string]: ToolFunc;
203
- }
204
- /**
205
- * Describes a package of tool functions, including methods for registration and unregistration.
206
- * @interface
207
- */
208
- interface ToolFuncPackage {
209
- /**
210
- * The name of the tool function package.
211
- * @type {string}
212
- */
213
- name: string;
214
- /**
215
- * A method to register all functions within the package.
216
- * @param {any} [data] - Optional data to pass to the registration process.
217
- */
218
- register: (data?: any) => void;
219
- /**
220
- * An optional method to unregister all functions within the package.
221
- */
222
- unregister?: () => void;
223
- }
224
- /**
225
- * Declaration merging to extend the `ToolFunc` class with `BaseFunc` properties and allow arbitrary properties.
226
- */
227
- declare interface ToolFunc extends BaseFunc {
228
- [name: string]: any;
229
- }
230
- /**
231
- * A manager for creating, registering, and executing reusable tool functions.
232
- *
233
- * `ToolFunc` provides a robust framework for defining functions with rich metadata,
234
- * managing their lifecycle, and executing them through a centralized registry.
235
- * It is the core component for creating modular and discoverable tools.
236
- *
237
- * Key Features:
238
- * - **Rich Metadata**: Define functions with descriptions, parameters, tags, and titles, making them self-documenting.
239
- * - **Static Registry**: A global, static registry (`ToolFunc.items`) allows any part of an application to access and run registered functions by name.
240
- * - **Dependency Management**: Use the `depends` property to declare dependencies on other `ToolFunc`s, which are then auto-registered.
241
- * - **Aliasing**: Assign multiple names to a function for flexibility.
242
- * - **Lifecycle Hooks**: Use the `setup` method for one-time initialization logic when a `ToolFunc` instance is created.
243
- * - **Parameter Handling**: Automatically handles both positional and named parameters.
244
- *
245
- * @extends AdvancePropertyManager
246
- *
247
- * @example
248
- * // 1. Define a helper function
249
- * const getUser = new ToolFunc({
250
- * name: 'getUser',
251
- * description: 'Retrieves a user by ID.',
252
- * params: { id: { type: 'string', required: true } },
253
- * func: (params) => ({ id: params.id, name: 'John Doe' }),
254
- * });
255
- *
256
- * // 2. Define a main function that depends on the helper
257
- * const welcomeUser = new ToolFunc({
258
- * name: 'welcomeUser',
259
- * title: 'Welcome User',
260
- * description: 'Generates a welcome message for a user.',
261
- * params: { userId: 'string' },
262
- * depends: {
263
- * // By declaring this dependency, `getUser` will be auto-registered
264
- * // when `welcomeUser` is registered.
265
- * userFetcher: getUser,
266
- * },
267
- * func: function(params) {
268
- * // `this` is the ToolFunc instance, so we can use `runSync`
269
- * const user = this.runSync('userFetcher', { id: params.userId });
270
- * return `Hello, ${user.name}!`;
271
- * },
272
- * });
273
- *
274
- * // 3. Register the main function. The dependency is registered automatically.
275
- * welcomeUser.register();
276
- *
277
- * // 4. Run the function from anywhere using the static runner.
278
- * async function main() {
279
- * const message = await ToolFunc.run('welcomeUser', { userId: '123' });
280
- * console.log(message); // Outputs: "Hello, John Doe!"
281
- * }
282
- *
283
- * main();
284
- */
285
- declare class ToolFunc extends AdvancePropertyManager {
286
- /**
287
- * A static registry of all `ToolFunc` instances, indexed by name.
288
- * @type {Funcs}
289
- */
290
- static items: Funcs;
291
- /**
292
- * A static map of aliases to their corresponding function names.
293
- * @type {{ [name: string]: string }}
294
- */
295
- static aliases: {
296
- [name: string]: string;
297
- };
298
- /**
299
- * A conventional property to designate a file path for saving the registered `ToolFunc` data.
300
- * Note: The `ToolFunc` class itself does not implement persistence logic. It is up to the
301
- * developer to use this path to save and load the `ToolFunc.items` registry if needed.
302
- * @type {string}
303
- */
304
- static dataPath: string;
305
- /**
306
- * Retrieves a registered function by its name or alias.
307
- * @param {string} name - The name or alias of the function to retrieve.
308
- * @returns {ToolFunc | undefined} The `ToolFunc` instance if found, otherwise `undefined`.
309
- */
310
- static get(name: string): ToolFunc;
311
- /**
312
- * Returns the complete map of all registered functions.
313
- * @returns {Funcs} The map of `ToolFunc` instances.
314
- */
315
- static list(): Funcs;
316
- /**
317
- * Finds the first registered function that has a specific tag.
318
- * @param {string} tagName - The tag to search for.
319
- * @returns {ToolFunc | undefined} The first matching `ToolFunc` instance, or `undefined` if none is found.
320
- */
321
- static getByTag(tagName: string): ToolFunc | undefined;
322
- /**
323
- * Retrieves all registered functions that have a specific tag.
324
- * @param {string} tagName - The tag to search for.
325
- * @returns {ToolFunc[]} An array of matching `ToolFunc` instances.
326
- */
327
- static getAllByTag(tagName: string): ToolFunc[];
328
- /**
329
- * Checks if any registered function has a specific asynchronous feature.
330
- * @param {AsyncFeatureBits} feature - The async feature bit to check for.
331
- * @returns {boolean} `true` if the feature is present in any function, otherwise `false`.
332
- */
333
- static hasAsyncFeature(feature: AsyncFeatureBits): boolean;
334
- /**
335
- * Asynchronously executes a registered function by name with named parameters.
336
- * @param {string} name - The name of the function to run.
337
- * @param {any} [params] - The parameters object for the function.
338
- * @returns {Promise<any>} A promise that resolves with the function's result.
339
- * @throws {NotFoundError} If the function with the given name is not found.
340
- */
341
- static run(name: string, params?: any): Promise<any>;
342
- /**
343
- * Synchronously executes a registered function by name with named parameters.
344
- * @param {string} name - The name of the function to run.
345
- * @param {any} [params] - The parameters object for the function.
346
- * @returns {any} The result of the function's execution.
347
- * @throws {NotFoundError} If the function with the given name is not found.
348
- */
349
- static runSync(name: string, params?: any): any;
350
- /**
351
- * Retrieves a bound, runnable function reference for a registered function.
352
- * This reference is suitable for execution with an object of named parameters.
353
- * @param {string} name - The name of the function.
354
- * @returns {Function | undefined} A bound function reference, or `undefined` if not found.
355
- */
356
- static getFunc(name: string): any;
357
- /**
358
- * Asynchronously executes a function using positional arguments.
359
- * @param {string} name - The name of the function to run.
360
- * @param {...any[]} params - Positional arguments to pass to the function.
361
- * @returns {Promise<any>} A promise that resolves with the function's result.
362
- * @throws {NotFoundError} If the function with the given name is not found.
363
- */
364
- static runWithPos(name: string, ...params: any[]): Promise<any>;
365
- /**
366
- * Synchronously executes a function using positional arguments.
367
- * @param {string} name - The name of the function to run.
368
- * @param {...any[]} params - Positional arguments to pass to the function.
369
- * @returns {any} The result of the function's execution.
370
- * @throws {NotFoundError} If the function with the given name is not found.
371
- */
372
- static runWithPosSync(name: string, ...params: any[]): any;
373
- /**
374
- * Retrieves a bound, runnable function reference for a registered function.
375
- * This reference is suitable for execution with positional arguments.
376
- * @param {string} name - The name of the function.
377
- * @returns {Function | undefined} A bound function reference, or `undefined` if not found.
378
- */
379
- static getFuncWithPos(name: string): any;
380
- /**
381
- * Registers a new tool function.
382
- *
383
- * @overload
384
- * @param {string} name - The name of the function.
385
- * @param {FuncItem} options - The function's configuration.
386
- * @returns {boolean | ToolFunc} The new `ToolFunc` instance, or `false` if a function with that name already exists.
387
- *
388
- * @overload
389
- * @param {Function} func - The function implementation.
390
- * @param {FuncItem} options - The function's configuration.
391
- * @returns {boolean | ToolFunc} The new `ToolFunc` instance, or `false` if a function with that name already exists.
392
- *
393
- * @overload
394
- * @param {string | ToolFunc | Function | FuncItem} name - A name, `ToolFunc` instance, function, or configuration object.
395
- * @param {FuncItem} [options] - Additional configuration.
396
- * @returns {boolean | ToolFunc} The new `ToolFunc` instance, or `false` if a function with that name already exists.
397
- */
398
- static register(name: string, options: FuncItem): boolean | ToolFunc;
399
- static register(func: Function, options: FuncItem): boolean | ToolFunc;
400
- static register(name: string | ToolFunc | Function | FuncItem, options?: FuncItem): boolean | ToolFunc;
401
- /**
402
- * Unregisters a function by its name, also removing any associated aliases.
403
- * @param {string} name - The name of the function to unregister.
404
- * @returns {ToolFunc | undefined} The unregistered `ToolFunc` instance, or `undefined` if it was not found.
405
- */
406
- static unregister(name: string): ToolFunc | undefined;
407
- /**
408
- * Initializes a new `ToolFunc` instance.
409
- *
410
- * @param {string | Function | FuncItem} name - Can be a function name, a function implementation, or a configuration object.
411
- * @param {FuncItem | any} [options={}] - Configuration options if not provided in the first argument.
412
- */
413
- constructor(name: string | Function | FuncItem, options?: FuncItem | any);
414
- /**
415
- * Registers the current `ToolFunc` instance into the static registry.
416
- * Also registers any declared dependencies.
417
- * @returns {boolean | ToolFunc} The instance itself upon successful registration, or `false` if it already exists.
418
- */
419
- register(): boolean | ToolFunc;
420
- /**
421
- * Removes the current `ToolFunc` instance from the static registry.
422
- * @returns {ToolFunc | undefined} The instance that was unregistered.
423
- */
424
- unregister(): any;
425
- /**
426
- * Converts an array of positional arguments into a named parameters object.
427
- * This is used internally to support functions defined with named parameters.
428
- * @param {any[]} params - An array of positional arguments.
429
- * @returns {any[]} An array containing a single parameters object.
430
- */
431
- arr2ObjParams(params: any[]): any[];
432
- /**
433
- * Converts a named parameters object into an array of positional arguments.
434
- * This is used for functions defined with positional parameters.
435
- * @param {any} [params] - A named parameters object.
436
- * @returns {any[]} An array of positional arguments.
437
- */
438
- obj2ArrParams(params?: any): any[];
439
- /**
440
- * Executes the function synchronously with a named parameters object.
441
- * @param {any} [params] - The parameters object for the function.
442
- * @returns {any} The result of the function execution.
443
- * @throws Will throw an error if an array of parameters is passed to a function that expects an object.
444
- */
445
- runSync(params?: any): any;
446
- /**
447
- * Executes the function asynchronously with a named parameters object.
448
- * @param {any} [params] - The parameters object for the function.
449
- * @returns {Promise<any>} A promise that resolves with the function's result.
450
- */
451
- run(params?: any): Promise<any>;
452
- /**
453
- * Asynchronously executes another registered function by name.
454
- * This method delegates to `runAsSync()` internally.
455
- * @param {string} name - The name of the target function to run.
456
- * @param {any} [params] - Optional parameters to pass to the function.
457
- * @returns {Promise<any>} A promise that resolves with the result of the function execution.
458
- */
459
- runAs(name: string, params?: any): Promise<any>;
460
- /**
461
- * Synchronously executes another registered function by name.
462
- * This is a convenience method that forwards the call to the static `runSync()` method.
463
- * @param {string} name - The name of the target function to run.
464
- * @param {any} [params] - Optional parameters to pass to the function.
465
- * @returns {any} The result of the function execution.
466
- */
467
- runAsSync(name: string, params?: any): any;
468
- /**
469
- * Gets a bound function reference for execution with named parameters.
470
- * If a name is provided, it retrieves a different function from the registry.
471
- * Otherwise, it returns a bound version of this instance's `runSync`.
472
- * @param {string} [name] - Optional name of the function to retrieve.
473
- * @returns {Function | undefined} A function reference or `undefined` if not found.
474
- */
475
- getFunc(name?: string): any;
476
- /**
477
- * Executes the function synchronously using positional arguments.
478
- * If the function expects named parameters, it converts the arguments automatically.
479
- * @param {...any[]} params - Positional arguments passed to the function.
480
- * @returns {any} The result of the function execution.
481
- */
482
- runWithPosSync(...params: any[]): any;
483
- /**
484
- * Synchronously executes another function by name using positional arguments.
485
- * This is a convenience wrapper around the static `runWithPosSync()` method.
486
- * @param {string} name - The name of the target function to run.
487
- * @param {...any[]} params - Positional arguments to pass to the function.
488
- * @returns {any} The result of the function execution.
489
- */
490
- runWithPosAsSync(name: string, ...params: any[]): any;
491
- /**
492
- * Executes the function asynchronously using positional arguments.
493
- * Delegates to `runWithPosSync()` internally.
494
- * @param {...any[]} params - Positional arguments passed to the function.
495
- * @returns {Promise<any>} A promise that resolves with the result of the function execution.
496
- */
497
- runWithPos(...params: any[]): Promise<any>;
498
- /**
499
- * Asynchronously executes another function by name using positional arguments.
500
- * Delegates to `runWithPosAsSync()` internally.
501
- * @param {string} name - The name of the target function to run.
502
- * @param {...any[]} params - Positional arguments to pass to the function.
503
- * @returns {Promise<any>} A promise that resolves with the result of the function execution.
504
- */
505
- runWithPosAs(name: string, ...params: any[]): Promise<any>;
506
- /**
507
- * Gets a bound function reference suitable for positional argument execution.
508
- * If a name is provided, it retrieves a different function from the registry.
509
- * Otherwise, it returns a bound version of this instance's `runWithPosSync`.
510
- * @param {string} [name] - Optional name of the function to retrieve.
511
- * @returns {Function | undefined} A function reference or `undefined` if not found.
512
- */
513
- getFuncWithPos(name?: string): any;
514
- /**
515
- * Checks if the current function instance supports a specific async feature.
516
- * @param {AsyncFeatureBits} feature - The async feature bit to check for.
517
- * @returns {boolean} `true` if the feature is supported, otherwise `false`.
518
- */
519
- hasAsyncFeature(feature: AsyncFeatureBits): boolean;
520
- /**
521
- * Determines if a function call should produce a stream.
522
- *
523
- * The logic is as follows:
524
- * 1. It first checks if the function is generally capable of streaming (`this.stream`).
525
- * 2. If it is, it then checks if a `stream` parameter is formally declared in the function's `params` definition.
526
- * 3. If both are true, the method returns the value of the `stream` property from the runtime `params` object.
527
- * Otherwise, it returns the function's static `stream` capability.
528
- *
529
- * @param {any} params - The runtime parameters passed to the function call.
530
- * @returns {boolean | undefined} `true` if the call should be streamed, `false` or `undefined` otherwise.
531
- */
532
- isStream(params: any): boolean | undefined;
533
- }
534
- /**
535
- * Defines the schema for `ToolFunc` properties, used by `AdvancePropertyManager`.
536
- * This controls how properties are assigned and exported.
537
- * @internal
538
- */
539
- declare const ToolFuncSchema: {
540
- name: {
541
- type: string;
542
- };
543
- description: {
544
- type: string;
545
- };
546
- title: {
547
- type: string;
548
- };
549
- func: {
550
- type: string;
551
- assign(value: Function | string, dest: ToolFunc, src?: ToolFunc, name?: string, options?: any): string | Function;
552
- };
553
- params: {
554
- type: string;
555
- };
556
- result: {
557
- type: string;
558
- };
559
- setup: {
560
- type: string;
561
- };
562
- depends: {
563
- type: string;
564
- exported: boolean;
565
- };
566
- tags: {
567
- type: string[];
568
- };
569
- isApi: {
570
- type: string;
571
- };
572
- stream: {
573
- type: string;
574
- };
575
- asyncFeatures: {
576
- type: string;
577
- };
578
- alias: {
579
- type: string[];
580
- };
581
- };
582
- /**
583
- * A unique symbol used to attach metadata to a function object.
584
- * @internal
585
- */
586
- declare const FuncMetaSymbol: unique symbol;
587
- /**
588
- * Attaches metadata to a function or `ToolFunc` object.
589
- *
590
- * This utility merges the provided metadata with any existing metadata on the target.
591
- *
592
- * @param {Function | ToolFunc} fn - The function or `ToolFunc` instance to which metadata will be added.
593
- * @param {any} meta - The metadata object to attach. The operation is skipped if this is not a non-null object.
594
- * @param {boolean} [ignoreExists=true] - If `true`, new metadata overwrites existing keys. If `false`, it merges deeply, preserving existing values.
595
- * @returns {Function | ToolFunc | undefined} The updated function or `ToolFunc` with metadata, or `undefined` if the operation was skipped.
596
- */
597
- declare function funcWithMeta(fn: Function | ToolFunc, meta: any, ignoreExists?: boolean): Function | ToolFunc | undefined;
598
- /**
599
- * Retrieves metadata associated with a function or `ToolFunc` instance.
600
- *
601
- * @param {Function | ToolFunc} fn - The function or `ToolFunc` instance from which to retrieve metadata.
602
- * @returns {any} The metadata as a plain object, or `undefined` if no metadata is found.
603
- */
604
- declare function funcGetMeta(fn: Function | ToolFunc): any;
605
-
606
- /**
607
- * A constant representing a passing score, likely used for similarity or relevance thresholds.
608
- */
609
- declare const PASSING_SCORE = 0.618;
610
- /**
611
- * A tuple of supported action names for remote tool interactions.
612
- */
613
- declare const ActionNames: readonly ["get", "post", "put", "delete", "patch", "list", "res"];
614
- /**
615
- * Represents a valid action name for a remote tool, derived from the `ActionNames` tuple.
616
- */
617
- type ActionName = typeof ActionNames[number];
618
- /**
619
- * Defines the signature for a function that processes an AI model's name,
620
- * typically for matching or validation purposes.
621
- * @param name - The model name string.
622
- * @returns A string, a RegExp execution array, or undefined if no match is found.
623
- */
624
- type AIModelNameRuleFn = (name: string) => string | RegExpExecArray | undefined;
625
- /**
626
- * Defines a single rule for matching an AI model name. It can be a simple string,
627
- * a regular expression, or a custom function.
628
- */
629
- type AIModelNameRule = string | RegExp | AIModelNameRuleFn;
630
- /**
631
- * Represents a collection of one or more AI model name matching rules.
632
- */
633
- type AIModelNameRules = AIModelNameRule | AIModelNameRule[];
634
- /**
635
- * A schema object defining properties common to all remote tool functions.
636
- * This is used by `AdvancePropertyManager` to define how these properties are handled.
637
- * @internal
638
- */
639
- declare const RemoteToolFuncSchema: {
640
- /**
641
- * The action for the remote call. This is primarily interpreted as an RPC method name.
642
- * For HTTP transports, it defaults to being sent as a custom RPC method name (e.g., via POST).
643
- * Only specific RESTful server implementations might map certain 'action' values (like 'get', 'delete')
644
- * to corresponding HTTP methods. Defaults to 'post'.
645
- */
646
- action: {
647
- type: string;
648
- assign(value: ActionName, dest: any, src?: any, name?: string, options?: any): "get" | "post" | "put" | "delete" | "patch" | "list" | "res";
649
- };
650
- /**
651
- * Optional fetch options, primarily for use with HTTP-based transports.
652
- * @deprecated Use `transport` instead.
653
- */
654
- fetchOptions: {
655
- type: string;
656
- };
657
- /**
658
- * If true, allows the function's body to be exported to the client for local execution.
659
- * This is a server-side setting.
660
- */
661
- allowExportFunc: {
662
- type: string;
663
- };
664
- };
665
- /**
666
- * Base interface for a remote function's configuration, extending `BaseFuncItem`
667
- * with properties required for remote execution.
668
- */
669
- interface RemoteFuncItem extends BaseFuncItem {
670
- /**
671
- * The root endpoint for the remote service.
672
- * @type {string}
673
- * @deprecated Use `transport` instead.
674
- */
675
- apiRoot?: string;
676
- /**
677
- * The action to be used for the remote call. This typically represents an RPC method name.
678
- * Only for RESTful HTTP transports, it might be mapped to a standard HTTP method (e.g., GET, POST)
679
- * @type {ActionName}
680
- */
681
- action?: ActionName;
682
- /**
683
- * Addtional options to be passed to the underlying `fetch` call in a transport.
684
- * @type {any}
685
- */
686
- fetchOptions?: any;
687
- }
688
-
689
- declare class Deque<T = any> extends Array<T> {
690
- private _capacity;
691
- private _length;
692
- private _front;
693
- private _disableAutoResize?;
694
- constructor(capacity?: number | T[], disableAutoResize?: boolean);
695
- push(item: T): number;
696
- unshift(item: T): number;
697
- /**
698
- * Removes and returns the element at the back of the deque.
699
- *
700
- * @param skipNull When `true`, skips trailing `null`/`undefined` values until a valid element is found or all elements are processed.
701
- * @returns The removed element, or `undefined` if the deque is empty or all elements are skipped.
702
- *
703
- * @example
704
- * // Normal pop without skipping
705
- * const deque = new Deque([1, 2, 3]);
706
- * deque.pop(); // 3
707
- *
708
- * @example
709
- * // Skipping null values
710
- * const nullDeque = new Deque([null, 4, null]);
711
- * nullDeque.pop(true); // 4
712
- * nullDeque.pop(true); // undefined (skipped remaining nulls)
713
- *
714
- * @example
715
- * // Mixed elements with skip
716
- * const mixedDeque = new Deque([5, null, 6, null]);
717
- * mixedDeque.pop(true); // 6
718
- * mixedDeque.pop(false); // null (explicitly not skipping)
719
- */
720
- pop(skipNull?: boolean): T | undefined;
721
- /**
722
- * Removes and returns the element at the front of the deque.
723
- *
724
- * @param skipNull When `true`, skips leading `null`/`undefined` values until a valid element is found or all elements are processed.
725
- * @returns The removed element, or `undefined` if the deque is empty or all elements are skipped.
726
- *
727
- * @example
728
- * // Normal shift without skipping
729
- * const deque = new Deque([1, 2, 3]);
730
- * deque.shift(); // 1
731
- *
732
- * @example
733
- * // Skipping null values
734
- * const nullDeque = new Deque([null, 4, null]);
735
- * nullDeque.shift(true); // 4
736
- * nullDeque.shift(true); // undefined (skipped remaining nulls)
737
- *
738
- * @example
739
- * // Mixed elements with skip
740
- * const mixedDeque = new Deque([null, 5, null, 6]);
741
- * mixedDeque.shift(true); // 5
742
- * mixedDeque.shift(false); // null (explicitly not skipping)
743
- */
744
- shift(skipNull?: boolean): T | undefined;
745
- /**
746
- * Gets the number of elements in the deque.
747
- *
748
- * @returns The current count of elements in the deque.
749
- *
750
- * @example
751
- * const deque = new Deque([1, 2, 3]);
752
- * console.log(deque.size); // 3
753
- *
754
- * @important
755
- * Do NOT use the native `Array.length` property. The Deque implementation uses a circular buffer with capacity management, so the native `length` reflects the underlying array capacity, not the actual element count. Always use `size` to get the correct element count.
756
- */
757
- get size(): number;
758
- get(index: number): T | undefined;
759
- peekBack(): T | undefined;
760
- peekFront(): T | undefined;
761
- clear(): void;
762
- isEmpty(): boolean;
763
- /**
764
- * Removes the element at the specified index.
765
- * @param index Logical index position (0 represents the front, length-1 represents the back)
766
- * @returns The removed element
767
- */
768
- removeAt(index: number): T | undefined;
769
- private checkCapacity;
770
- private resizeTo;
771
- }
772
-
773
- declare const DefaultAsyncSemaphoreCapacity = 32;
774
- type SemaphoreIsReadyFuncType = () => Promise<boolean> | boolean;
775
- interface BinarySemaphoreOptions {
776
- initFn?: () => any;
777
- pauseFn?: () => void;
778
- resumeFn?: () => void;
779
- capacity?: number;
780
- }
781
- interface BinarySemaphoreAcquireOptions {
782
- signal?: AbortSignal;
783
- [n: string]: any;
784
- }
785
- interface BinarySemaphoreReleaseOptions {
786
- token?: any;
787
- [n: string]: any;
788
- }
789
- interface BinarySemaphoreReleaserFunc extends BinarySemaphoreReleaseOptions {
790
- (): void;
791
- }
792
- interface SemaphoreOptions extends BinarySemaphoreOptions {
793
- maxConcurrency?: number;
794
- isReadyFn?: SemaphoreIsReadyFuncType;
795
- }
796
- interface SemaphoreTaskItem extends BinarySemaphoreAcquireOptions {
797
- resolve: (value: any) => void;
798
- reject: (reason?: any) => void;
799
- token?: any;
800
- }
801
- /**
802
- * A binary semaphore implementation for managing concurrency in asynchronous operations.
803
- * Unlike a general semaphore, a binary semaphore allows only one caller to acquire the semaphore at a time.
804
- * It provides methods to acquire, release, and manage waiting tasks efficiently.
805
- *
806
- * Example usage:
807
- *
808
- * ```typescript
809
- * const semaphore = new Semaphore(5); // Allows 5 concurrent operations.
810
- *
811
- * const semaphore = new Semaphore(
812
- * 4, // Allow 4 concurrent async calls
813
- * {
814
- * capacity: 100 // Prealloc space for 100 tokens
815
- * }
816
- * );
817
- *
818
- * async function fetchData(x) {
819
- * await semaphore.acquire()
820
- * try {
821
- * console.log(semaphore.pendingCount + ' calls to fetch are waiting')
822
- * // ... do some async stuff with x
823
- * } finally {
824
- * semaphore.release();
825
- * }
826
- * }
827
- *
828
- * const data = await Promise.all(array.map(fetchData));
829
- * ```
830
- */
831
- declare class BinarySemaphore {
832
- readonly waiting: Deque<SemaphoreTaskItem | undefined>;
833
- protected free: any;
834
- protected emitter: EventEmitter;
835
- protected useDefaultTokens: boolean;
836
- protected pauseFn?: () => void;
837
- protected resumeFn?: () => void;
838
- protected initTokenFn: (token?: any) => void;
839
- protected paused: boolean;
840
- protected _activeCount: number;
841
- /**
842
- * Creates a binary semaphore object for managing concurrency in asynchronous operations.
843
- *
844
- * @param options.initFn Function that is used to initialize the tokens used to manage the semaphore. The default is () => '1'.
845
- * @param options.pauseFn An optional fuction that is called to opportunistically request pausing the the incoming stream of data,
846
- * instead of piling up waiting promises and possibly running out of memory. See examples/pausing.js.
847
- * @param options.resumeFn An optional function that is called when there is room again to accept new waiters on the semaphore.
848
- * This function must be declared if a pauseFn is declared.
849
- * @param options.capacity Sets the size of the preallocated waiting list inside the semaphore.
850
- * This is typically used by high performance where the developer can make a rough estimate of the number of concurrent users of a semaphore.
851
- *
852
- * ```ts
853
- * const readline = require('readline');
854
- *
855
- * const rl = readline.createInterface({
856
- * input: process.stdin,
857
- * output: process.stdout,
858
- * terminal: false
859
- * });
860
- *
861
- * function pause() {
862
- * console.log('Pausing the stream');
863
- * rl.pause();
864
- * }
865
- *
866
- * function resume() {
867
- * console.log('Resuming the stream');
868
- * rl.resume();
869
- * }
870
- *
871
- * const s = new BinarySemaphore({ pauseFn: pause, resumeFn: resume });
872
- *
873
- * async function parse(line) {
874
- * await s.acquire();
875
- *
876
- * console.log(line);
877
- *
878
- * s.release();
879
- * }
880
- *
881
- * rl.on('line', line => {
882
- * parse(line).catch(console.error);
883
- * });
884
- * ```
885
- *
886
- */
887
- constructor(options?: BinarySemaphoreOptions);
888
- initFree(options?: BinarySemaphoreOptions): void;
889
- onReleased(options?: BinarySemaphoreReleaseOptions): void;
890
- init(options: BinarySemaphoreOptions): void;
891
- _newReleaser(options?: BinarySemaphoreReleaseOptions): BinarySemaphoreReleaserFunc;
892
- _dispatchTask(task: SemaphoreTaskItem, options?: BinarySemaphoreReleaseOptions): void;
893
- lock(options?: BinarySemaphoreAcquireOptions): any;
894
- unlock(token?: any): void;
895
- /**
896
- * Attempt to acquire a token from the semaphore, if one is available immediately. Otherwise, return undefined.
897
- *
898
- * @return Returns a token if the semaphore is not full; otherwise, returns `undefined`.
899
- */
900
- tryAcquire(options?: BinarySemaphoreAcquireOptions): any | undefined;
901
- /**
902
- * 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.
903
- * @param options.signal An optional AbortSignal to abort the acquisition process. If aborted, the promise will reject with an AbortError.
904
- * @return 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.
905
- */
906
- acquire(options?: BinarySemaphoreAcquireOptions): Promise<BinarySemaphoreReleaserFunc>;
907
- /**
908
- * Releases the semaphore, incrementing the number of free execution slots. If there are tasks in the waiting queue, the next task will be dispatched.
909
- * @param options.token Optional token returned by `acquire()` when using a custom `initFn`. If provided, it will be used to unlock the semaphore.
910
- */
911
- release(options?: BinarySemaphoreReleaseOptions): void;
912
- /**
913
- * 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.
914
- */
915
- drain(): Promise<any[]>;
916
- abort(reason?: any): void;
917
- /**
918
- * Get the total count of all active operations.
919
- *
920
- * This method returns the number of operations that are either:
921
- * - Waiting in the queue to acquire the semaphore (`pendingCount`).
922
- * - Already acquired the semaphore but have not yet released it.
923
- *
924
- * @returns {number} The total count of active operations, including both waiting and ongoing tasks.
925
- */
926
- get activeCount(): number;
927
- /**
928
- * Get the number of callers waiting on the semaphore, i.e. the number of pending promises.
929
- *
930
- * @returns The number of waiters in the waiting list.
931
- */
932
- get pendingCount(): number;
933
- }
934
- /**
935
- * A Semaphore implementation for managing concurrency in asynchronous operations.
936
- * Semaphores allow a fixed number of resources to be accessed concurrently.
937
- * This class extends BinarySemaphore and adds support for a maximum concurrency limit and an optional readiness check.
938
- *
939
- * Example usage:
940
- *
941
- * ```typescript
942
- * const semaphore = new Semaphore(5); // Allows 5 concurrent operations.
943
- *
944
- * const semaphore = new Semaphore(
945
- * 4, // Allow 4 concurrent async calls
946
- * {
947
- * capacity: 100, // Prealloc space for 100 tokens
948
- * isReadyFn: async () => {
949
- * // Check if the system is ready to handle more requests
950
- * return true;
951
- * },
952
- * pauseFn: () => {
953
- * console.log('Pausing the stream');
954
- * },
955
- * resumeFn: () => {
956
- * console.log('Resuming the stream');
957
- * }
958
- * }
959
- * );
960
- *
961
- * async function fetchData(x) {
962
- * await semaphore.acquire()
963
- * try {
964
- * console.log(semaphore.pendingCount() + ' calls to fetch are waiting')
965
- * // ... do some async stuff with x
966
- * } finally {
967
- * semaphore.release();
968
- * }
969
- * }
970
- *
971
- * const data = await Promise.all(array.map(fetchData));
972
- * ```
973
- */
974
- declare class Semaphore extends BinarySemaphore {
975
- readonly maxConcurrency: number;
976
- protected free: Deque<any>;
977
- private isReady?;
978
- /**
979
- * Creates a semaphore object. The first argument is the maximum concurrently number and the second argument is optional.
980
- *
981
- * @param maxConcurrency The maximum number of callers allowed to acquire the semaphore concurrently.
982
- * @param options.initFn Function that is used to initialize the tokens used to manage the semaphore. The default is () => '1'.
983
- * @param options.pauseFn An optional function that is called to opportunistically request pausing the incoming stream of data,
984
- * instead of piling up waiting promises and possibly running out of memory. See examples/pausing.js.
985
- * @param options.resumeFn An optional function that is called when there is room again to accept new waiters on the semaphore.
986
- * This function must be declared if a pauseFn is declared.
987
- * @param options.capacity Sets the size of the preallocated waiting list inside the semaphore.
988
- * This is typically used by high performance where the developer can make a rough estimate of the number of concurrent users of a semaphore.
989
- * @param options.isReadyFn An optional function that returns a boolean or a promise that resolves to a boolean indicating whether the semaphore is ready to accept new requests.
990
- */
991
- constructor(maxConcurrency: number | SemaphoreOptions, options?: SemaphoreOptions);
992
- initFree(options: SemaphoreOptions): void;
993
- tryAcquire(options?: BinarySemaphoreAcquireOptions): Promise<any | undefined> | any | undefined;
994
- unlock(token?: any): void;
995
- lock(options?: BinarySemaphoreAcquireOptions): any;
996
- drain(): Promise<any[]>;
997
- }
998
- /**
999
- * Creates a rate limiter function that blocks with a promise whenever the rate limit is hit and resolves the promise once the call rate is within the limit set by rps. The second argument is optional.
1000
- *
1001
- * @param rps
1002
- * @param options.timeUnit The `timeUnit` is an optional argument setting the width of the rate limiting window in milliseconds.
1003
- * The default `timeUnit` is 1000 ms, therefore making the rps argument act as requests per second limit.
1004
- * @param options.uniformDistribution The `uniformDistribution` argument enforces a discrete uniform distribution over time,
1005
- * instead of the default that allows hitting the function rps time and then pausing for timeWindow milliseconds. Setting
1006
- * the `uniformDistribution` option is mainly useful in a situation where the flow of rate limit function calls is continuous
1007
- * and and occuring faster than timeUnit (e.g. reading a file) and not enabling it would cause the maximum number of calls to
1008
- * resolve immediately (thus exhaust the limit immediately) and therefore the next bunch calls would need to wait for timeWindow
1009
- * milliseconds. However if the flow is sparse then this option may make the code run slower with no advantages.
1010
- *
1011
- * Examples:
1012
- *
1013
- * ```ts
1014
- * async function f() {
1015
- * const lim = RateLimit(5); // rps
1016
- *
1017
- * for (let i = 0; i < n; i++) {
1018
- * await lim();
1019
- * // ... do something async
1020
- * }
1021
- * }
1022
- * ```
1023
- *
1024
- *
1025
- */
1026
- declare function RateLimit(rps: number, { timeUnit, uniformDistribution, }?: {
1027
- timeUnit?: number;
1028
- uniformDistribution?: boolean;
1029
- }): () => Promise<void>;
1030
-
1031
- declare const ToolAsyncMultiTaskBit = 0;
1032
- declare const ToolAsyncCancelableBit = 1;
1033
- declare const ToolAsyncPriorityBit = 2;
1034
- declare enum AsyncFeatureBits {
1035
- MultiTask = 0,
1036
- Cancelable = 1,
1037
- Priority = 2
1038
- }
1039
- declare enum AsyncFeatures {
1040
- MultiTask = 1,// B0001
1041
- Cancelable = 2,// B010
1042
- Priority = 4
1043
- }
1044
- type AsyncTaskId = string | number;
1045
- interface CancelableAbilityOptions extends AbilityOptions {
1046
- asyncFeatures?: AsyncFeatures;
1047
- maxTaskConcurrency?: number;
1048
- isReadyFn?: SemaphoreIsReadyFuncType;
1049
- }
1050
- declare class TaskAbortController extends AbortController {
1051
- id?: AsyncTaskId;
1052
- timeoutId?: any;
1053
- streamController?: ReadableStreamDefaultController;
1054
- parent: CancelableAbility;
1055
- constructor(parent: CancelableAbility);
1056
- abort(reason?: string | Error | CommonError, data?: any): void;
1057
- throwRejected(alreadyRejected?: boolean): true | undefined;
1058
- }
1059
- interface TaskAbortControllers {
1060
- [k: AsyncTaskId]: TaskAbortController | undefined;
1061
- }
1062
- interface TaskPromise<T = any> extends Promise<T> {
1063
- task?: TaskAbortController;
1064
- }
1065
- declare interface CancelableAbility {
1066
- _asyncFeatures?: number;
1067
- _maxTaskConcurrency: number | undefined;
1068
- _isReadyFn?: SemaphoreIsReadyFuncType;
1069
- [name: string]: any;
1070
- }
1071
- declare class CancelableAbility {
1072
- generateAsyncTaskId: (taskId?: AsyncTaskId, aborters?: TaskAbortControllers) => AsyncTaskId;
1073
- cleanMultiTaskAborter: (id: AsyncTaskId, aborters: TaskAbortControllers) => void;
1074
- __task_aborter: TaskAbortController | TaskAbortControllers | undefined;
1075
- __task_semaphore: Semaphore | undefined;
1076
- get maxTaskConcurrency(): number | undefined;
1077
- get semaphore(): Semaphore | undefined;
1078
- getSemaphore(isReadyFn?: SemaphoreIsReadyFuncType | undefined): Semaphore | undefined;
1079
- static hasAsyncFeature(feature: AsyncFeatureBits): boolean;
1080
- hasAsyncFeature(feature: AsyncFeatureBits): boolean;
1081
- isAborted(taskId?: AsyncTaskId): boolean;
1082
- getRunningTask(taskId?: AsyncTaskId): TaskAbortController | undefined;
1083
- getRunningTaskCount(): number;
1084
- _generateAsyncTaskId(taskId?: AsyncTaskId, aborters?: TaskAbortControllers): AsyncTaskId;
1085
- $generateAsyncTaskId(taskId?: AsyncTaskId, aborters?: TaskAbortControllers): AsyncTaskId | undefined;
1086
- createAborter(params?: any, taskId?: AsyncTaskId, raiseError?: boolean): TaskAbortController;
1087
- $cleanMultiTaskAborter(id: AsyncTaskId, aborters: TaskAbortControllers): void;
1088
- cleanTaskAborter(aborter: TaskAbortController): void;
1089
- _cleanMultiTaskAborter(id: AsyncTaskId, aborters: TaskAbortControllers): void;
1090
- createTaskPromise<Output = any>(runTask: (params: Record<string, any>, aborter: TaskAbortController) => Promise<Output>, params: Record<string, any>, options?: {
1091
- taskId?: AsyncTaskId;
1092
- raiseError?: boolean;
1093
- }): TaskPromise<Output>;
1094
- runAsyncCancelableTask<Output = any>(params: Record<string, any> | undefined, runTask: (params: Record<string, any>, aborter: TaskAbortController) => Promise<Output>, options?: {
1095
- taskId?: AsyncTaskId;
1096
- raiseError?: boolean;
1097
- isReadyFn?: SemaphoreIsReadyFuncType;
1098
- }): TaskPromise<Output>;
1099
- abort(reason?: string, data?: any): void;
1100
- }
1101
- declare const makeToolFuncCancelable: <T extends Function | (new (...args: any[]) => any)>(targetClass?: T | undefined, options?: AbilityOptions) => T & typeof CancelableAbility & (T extends new (...args: any[]) => any ? InstanceType<T> : T) & CancelableAbility;
1102
-
1103
- declare global {
1104
- // eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- It has to be an `interface` so that it can be merged.
1105
- interface SymbolConstructor {
1106
- readonly observable: symbol;
1107
- }
1108
- }
1109
-
1110
- /**
1111
- * @file Defines common types used across transports.
1112
- */
1113
-
1114
- /**
1115
- * The generic handler for a remote procedure call (RPC) method.
1116
- * It receives the parameters and returns the result.
1117
- * @param params - The parameters for the RPC method.
1118
- * @param context - Optional context, like the raw request object from the underlying framework.
1119
- * @returns The result of the RPC method.
1120
- */
1121
- type RpcMethodHandler = (params: any, context?: any) => Promise<any> | any;
1122
- interface IToolTransport {
1123
- Tools: typeof ToolFunc;
1124
- /**
1125
- * The root endpoint for the remote service.
1126
- * For HTTP, this is a URL. For IPC, it could be a channel name.
1127
- */
1128
- apiRoot: string;
1129
- /**
1130
- * Additional options for the transport start or fetch, passed by mount.
1131
- */
1132
- options?: any;
1133
- mount(Tools: typeof ToolFunc, apiRoot?: string, options?: any): any | Promise<any>;
1134
- [name: string]: any;
1135
- }
1136
- declare abstract class ToolTransport implements IToolTransport {
1137
- apiRoot: string;
1138
- Tools: typeof ToolFunc;
1139
- options?: any;
1140
- setApiRoot(apiRoot: string): void;
1141
- mount(Tools: typeof ToolFunc, apiRoot?: string, options?: any): any;
1142
- abstract _mount(Tools: typeof ToolFunc, apiRoot: string, options?: any): any | Promise<any>;
1143
- }
1144
-
1145
- /**
1146
- * Defines the public interface for a client-side transport,
1147
- * responsible for communicating with a ServerTransport.
1148
- */
1149
- interface IClientToolTransport extends IToolTransport {
1150
- /**
1151
- * Connects to the server's discovery endpoint to get the list of available tools.
1152
- * @returns A promise that resolves to a map of tool function metadata.
1153
- */
1154
- loadApis(): Promise<Funcs>;
1155
- mount(clientTools: typeof ClientTools, apiPrefix?: string, options?: any): any | Promise<any>;
1156
- /**
1157
- * Fetches data from the server.
1158
- * @param name The name of the tool function to fetch.
1159
- * @param args The object parameters to pass to the server.
1160
- * @param act The action to perform on the server.
1161
- * @param subName The name of the sub-resource to fetch.
1162
- * @param options Additional options for the fetch call.
1163
- * @returns A promise that resolves with the fetched data.
1164
- */
1165
- fetch(name: string, args?: any, act?: ActionName | string, subName?: any, options?: any): any | Promise<any>;
1166
- [name: string]: any;
1167
- }
1168
- /**
1169
- * A concrete client transport implementation that uses the browser/node `fetch` API.
1170
- */
1171
- declare abstract class ClientToolTransport extends ToolTransport implements IClientToolTransport {
1172
- apiRoot: string;
1173
- Tools: typeof ClientTools;
1174
- constructor(apiRoot: string);
1175
- _mount(clientTools: typeof ClientTools, apiPrefix: string, options?: any): Promise<Funcs>;
1176
- /**
1177
- * Connects to the server's discovery endpoint to get the list of available tools.
1178
- * @returns A promise that resolves to a map of tool function metadata.
1179
- */
1180
- loadApis(): Promise<Funcs>;
1181
- fetch(name: string, args?: any, act?: ActionName | string, subName?: any, fetchOptions?: any): Promise<any>;
1182
- abstract _fetch(name: string, args?: any, act?: ActionName | string, subName?: any, fetchOptions?: any): any | Promise<any>;
1183
- abstract toObject(res: any, args?: any): any | Promise<any>;
1184
- }
1185
-
1186
- /**
1187
- * Alias for `RemoteFuncItem` on the client side.
1188
- */
1189
- interface ClientFuncItem extends RemoteFuncItem {
1190
- }
1191
- /**
1192
- * Declaration merging to extend the `ClientTools` class with `ClientFuncItem` properties.
1193
- */
1194
- declare interface ClientTools extends ClientFuncItem {
1195
- [name: string]: any;
1196
- }
1197
- /**
1198
- * Represents a client-side proxy for a remote tool function.
1199
- *
1200
- * A `ClientTools` instance is a `ToolFunc` that, when executed, does not run
1201
- * local code. Instead, it serializes the parameters and uses an injected
1202
- * transport layer (`IClientToolTransport`) to make a remote procedure call
1203
- * to its corresponding `ServerTools` counterpart.
1204
- *
1205
- * These tools are typically created dynamically by loading definitions from a server.
1206
- */
1207
- declare class ClientTools extends ToolFunc {
1208
- static action?: ActionName | string;
1209
- private static _transport;
1210
- /**
1211
- * Gets the root URL for API endpoints from the configured transport.
1212
- * This is used as the base for constructing request URLs.
1213
- */
1214
- static get apiRoot(): string;
1215
- /**
1216
- * Injects the client-side transport implementation. This is a crucial step
1217
- * to enable communication with the server.
1218
- * @param {IClientToolTransport} transport - The transport instance to use for all client-server communication.
1219
- */
1220
- static setTransport(transport: IClientToolTransport): void;
1221
- static get transport(): IClientToolTransport;
1222
- /**
1223
- * Loads tool definitions from the remote server via the configured transport.
1224
- * This method populates the local `ToolFunc` registry with `ClientTools` stubs.
1225
- */
1226
- static loadFrom(items?: Funcs): Promise<Funcs>;
1227
- /**
1228
- * Synchronously loads tool definitions from a provided object, registering
1229
- * each one as a `ClientTools` instance.
1230
- * @param items - A map of tool function metadata, typically from a server.
1231
- */
1232
- static loadFromSync(items: Funcs): void;
1233
- static fetch(name: string, objParam?: any, ...args: any[]): Promise<any>;
1234
- /**
1235
- * Gets the root URL for API endpoints from the configured transport.
1236
- * This is used as the base for constructing request URLs.
1237
- */
1238
- get apiRoot(): string;
1239
- fetch(objParam?: any, act?: ActionName, subName?: any, fetchOptions?: any): Promise<any>;
1240
- /**
1241
- * The core implementation for a client-side tool. When a `ClientTools` instance
1242
- * is "run", this `func` method is executed. It delegates the call to the
1243
- * configured transport, which handles the network communication.
1244
- *
1245
- * @param objParam - The parameters to send to the remote tool.
1246
- * @param objParam.stream [boolean] - the optional stream flag. if true, the tool will return a stream(ReadableStream).
1247
- * @returns The result from the remote tool.
1248
- */
1249
- func(objParam: any): Promise<any>;
1250
- }
1251
- /**
1252
- * The schema definition for `ClientTools` properties.
1253
- * @internal
1254
- */
1255
- declare const ClientToolFuncSchema: {
1256
- action: {
1257
- type: string;
1258
- assign(value: ActionName, dest: any, src?: any, name?: string, options?: any): "get" | "post" | "put" | "delete" | "patch" | "list" | "res";
1259
- };
1260
- fetchOptions: {
1261
- type: string;
1262
- };
1263
- allowExportFunc: {
1264
- type: string;
1265
- };
1266
- };
1267
-
1268
- /**
1269
- * Defines the structure for parameters passed to a `ServerTools` function.
1270
- * By convention, it includes optional `_req` and `_res` properties for direct
1271
- * access to the underlying transport's request and response objects (e.g., from Node.js http).
1272
- */
1273
- interface ServerFuncParams {
1274
- /**
1275
- * The underlying request object from the transport layer (e.g., `IncomingMessage`).
1276
- * @type {any}
1277
- */
1278
- _req?: any;
1279
- /**
1280
- * The underlying response or reply object from the transport layer (e.g., `ServerResponse`).
1281
- * @type {any}
1282
- */
1283
- _res?: any;
1284
- [name: string]: any;
1285
- }
1286
- /**
1287
- * Configuration interface for a `ServerTools` item.
1288
- * Extends `RemoteFuncItem` with server-specific options.
1289
- */
1290
- interface ServerFuncItem extends RemoteFuncItem {
1291
- /**
1292
- * If set to true, the body of the function (`func`) will be serialized and sent
1293
- * to the client when tools are loaded. This allows the client to execute the
1294
- * function locally instead of making a remote call. Defaults to false.
1295
- * @type {boolean}
1296
- */
1297
- allowExportFunc?: boolean;
1298
- }
1299
- /**
1300
- * Declaration merging to extend the `ServerTools` class with `ServerFuncItem` properties.
1301
- */
1302
- declare interface ServerTools extends ServerFuncItem {
1303
- [name: string]: any;
1304
- }
1305
- /**
1306
- * Represents a function that runs on a server and can be exposed to clients.
1307
- *
1308
- * `ServerTools` extends `ToolFunc` by adding logic for serialization and handling
1309
- * server-side execution contexts. It is designed to work with a transport layer
1310
- * (see `transports`) to expose its registered functions over a network.
1311
- */
1312
- declare class ServerTools extends ToolFunc {
1313
- private static _apiRoot?;
1314
- /**
1315
- * The conventional root path for the API endpoint.
1316
- */
1317
- static get apiRoot(): string | undefined;
1318
- static setApiRoot(v: string): void;
1319
- /**
1320
- * Serializes all registered `ServerTools` instances into a JSON object.
1321
- * This method is typically called by a transport's discovery endpoint.
1322
- *
1323
- * It filters for tools that are instances of `ServerTools` or marked as `isApi`.
1324
- * It omits the `func` body from the output unless `allowExportFunc` is true.
1325
- *
1326
- * @returns A map of serializable tool definitions.
1327
- */
1328
- static toJSON(): {
1329
- [name: string]: ServerTools;
1330
- };
1331
- /**
1332
- * Overrides the base `run` method to inject transport-specific context.
1333
- * If a `context` object containing `req` and `reply` is provided, these are
1334
- * added to the parameters as `_req` and `_res` before execution.
1335
- *
1336
- * @param {ServerFuncParams} params - The parameters for the function.
1337
- * @param {{ req: any, reply: any }} [context] - The transport-level context.
1338
- * @returns The result of the function execution.
1339
- */
1340
- run(params: ServerFuncParams, context?: {
1341
- req: any;
1342
- reply: any;
1343
- }): Promise<any>;
1344
- /**
1345
- * Placeholder for the actual server-side function implementation.
1346
- * This method is intended to be defined when a `ServerTools` instance is created.
1347
- * @param params - The parameters for the function.
1348
- * @returns The result of the function.
1349
- */
1350
- func(params: ServerFuncParams): Promise<any> | any;
1351
- }
1352
- /**
1353
- * The schema definition for `ServerTools` properties.
1354
- * @internal
1355
- */
1356
- declare const ServerToolFuncSchema: {
1357
- action: {
1358
- type: string;
1359
- assign(value: ActionName, dest: any, src?: any, name?: string, options?: any): "get" | "post" | "put" | "delete" | "patch" | "list" | "res";
1360
- };
1361
- fetchOptions: {
1362
- type: string;
1363
- };
1364
- allowExportFunc: {
1365
- type: string;
1366
- };
1367
- };
1368
-
1369
- declare class EventToolFunc extends ToolFunc {
1370
- _emitter: EventEmitter;
1371
- description: string;
1372
- result: string;
1373
- get emitter(): EventEmitter;
1374
- func(): EventEmitter;
1375
- }
1376
- declare const event: EventToolFunc;
1377
-
1378
- declare const SecondaryCache: typeof Cache;
1379
- declare function _lrucache(this: ToolFunc, { key, value, options }?: {
1380
- key?: string;
1381
- value?: any;
1382
- options?: ICacheOptions | number;
1383
- }): Cache;
1384
- declare function createLRUCache(name: string, options?: ICacheOptions | number): ToolFunc;
1385
- declare const lrucache: ToolFunc;
1386
-
1387
- interface RpcMethodsClientFuncParams {
1388
- act?: string;
1389
- [name: string]: any;
1390
- }
1391
- declare class RpcMethodsClientTool extends ClientTools {
1392
- fetch(options: RpcMethodsClientFuncParams, action: ActionName, subName?: any, fetchOptions?: any): Promise<any>;
1393
- _func(action: ActionName, options: RpcMethodsClientFuncParams, fetchOptions?: any): Promise<any>;
1394
- func(options: RpcMethodsClientFuncParams): Promise<any>;
1395
- assignMethods(methods: string[]): void;
1396
- }
1397
- declare const RpcMethodsClientToolSchema: {
1398
- methods: {
1399
- type: string;
1400
- assign(value: string[], dest: RpcMethodsClientTool, src?: any, name?: string, options?: any): void;
1401
- };
1402
- };
1403
-
1404
- interface ResClientFuncParams extends RpcMethodsClientFuncParams {
1405
- id?: string | number;
1406
- }
1407
- interface ResClientTools {
1408
- get?({ id }: ResClientFuncParams): any;
1409
- post?(options: ResClientFuncParams): any;
1410
- put?({ id }: ResClientFuncParams): any;
1411
- delete?({ id }: ResClientFuncParams): any;
1412
- list?(options?: ResClientFuncParams): any;
1413
- }
1414
- declare class ResClientTools extends RpcMethodsClientTool {
1415
- fetch(options: ResClientFuncParams, action: ActionName, ...args: any[]): Promise<any>;
1416
- }
1417
-
1418
- type PubSubCtx<T = any> = {
1419
- event: string;
1420
- id?: string;
1421
- ts?: number;
1422
- from?: string;
1423
- meta?: any;
1424
- };
1425
-
1426
- /**
1427
- * Represents the client-side stream for a PubSub connection.
1428
- *
1429
- * This interface abstracts the underlying connection object (like an `EventSource`
1430
- * or `WebSocket` client) into a standardized event-based stream. It provides
1431
- * methods for listening to events, sending messages (for bidirectional transports),
1432
- * and managing the connection state.
1433
- */
1434
- interface PubSubClientStream {
1435
- /**
1436
- * A unique identifier for this specific stream instance.
1437
- * This ID is typically generated by the client transport and sent to the
1438
- * server to establish a stable session identity.
1439
- */
1440
- clientId: string;
1441
- /**
1442
- * The protocol being used for this stream (e.g., 'sse', 'ws', 'ipc').
1443
- */
1444
- protocol: 'sse' | 'ws' | 'ipc' | string;
1445
- /**
1446
- * Optional. Represents the state of the connection.
1447
- * This is provided for compatibility with the `EventSource.readyState`
1448
- * and `WebSocket.readyState` properties.
1449
- * (e.g., 0 for connecting, 1 for open, 2 for closed).
1450
- */
1451
- readyState?: number;
1452
- /**
1453
- * Registers a listener for a specific event from the server.
1454
- * @param event The name of the event to listen for.
1455
- * @param listener The callback function to execute when the event is received.
1456
- * It receives the event data and an optional context object.
1457
- */
1458
- on: (event: string, listener: (data: any, ctx?: PubSubCtx) => void) => any;
1459
- /**
1460
- * Removes a previously registered event listener.
1461
- * @param event The name of the event.
1462
- * @param listener The listener function to remove.
1463
- */
1464
- off: (event: string, listener: (data: any, ctx?: PubSubCtx) => void) => void;
1465
- /**
1466
- * Closes the connection stream.
1467
- */
1468
- close: () => void;
1469
- /**
1470
- * Optional. Sends a message from the client to the server.
1471
- * This method is only available for bidirectional transports like WebSockets or IPC.
1472
- * It is not supported by unidirectional transports like Server-Sent Events (SSE).
1473
- * @param event The name of the event to send.
1474
- * @param data The payload for the event.
1475
- * @param ctx Optional context for the PubSub operation.
1476
- */
1477
- send?: (event: string, data: any, ctx?: PubSubCtx) => void;
1478
- /**
1479
- * Optional alias for the `on` method for compatibility with the
1480
- * standard `EventTarget` interface.
1481
- */
1482
- addEventListener?: PubSubClientStream['on'];
1483
- /**
1484
- * Optional alias for the `off` method for compatibility with the
1485
- * standard `EventTarget` interface.
1486
- */
1487
- removeEventListener?: PubSubClientStream['off'];
1488
- }
1489
- /**
1490
- * Defines the interface for a client-side PubSub transport.
1491
- *
1492
- * This abstraction is responsible for creating and managing the connection
1493
- * stream (`PubSubClientStream`) to the server.
1494
- */
1495
- interface IPubSubClientTransport {
1496
- /**
1497
- * Establishes a connection to a server endpoint.
1498
- * @param url The full URL of the endpoint, or a path relative to the `apiRoot` that may have been configured on the transport.
1499
- * @param params Optional parameters for the connection, which might include
1500
- * things like authentication tokens, initial subscription topics, or a client ID.
1501
- * @returns A `PubSubClientStream` instance that represents the active connection.
1502
- */
1503
- connect: (url: string, params?: any) => PubSubClientStream | Promise<PubSubClientStream>;
1504
- /**
1505
- * Optional. Disconnects a given stream.
1506
- * While the `close` method exists on the stream itself, placing `disconnect`
1507
- * on the transport can be semantically clearer in some architectures.
1508
- * By default, this should delegate to `stream.close()`.
1509
- * @param stream The stream to disconnect.
1510
- */
1511
- disconnect?: (stream: PubSubClientStream) => void;
1512
- /**
1513
- * Optional. Configures the transport with a base URL.
1514
- * If implemented, this allows the transport to resolve relative paths
1515
- * passed to the `connect` method.
1516
- * @param apiRoot The base URL for the API.
1517
- */
1518
- setApiRoot?: (apiRoot: string) => void;
1519
- }
1520
-
1521
- /**
1522
- * Represents the unique identifier for a client connected to the PubSub transport.
1523
- * This ID is used for targeted message publishing.
1524
- */
1525
- type PubSubClientId = string;
1526
- /**
1527
- * Represents an active client connection session on the server.
1528
- * This object provides a standardized way for the `EventServer` to interact
1529
- * with a connection, regardless of the underlying transport protocol.
1530
- */
1531
- interface PubSubServerSession {
1532
- /**
1533
- * A unique identifier for the session, typically generated by the transport layer upon connection.
1534
- */
1535
- id: string;
1536
- /**
1537
- * The unique identifier for the client associated with this session.
1538
- */
1539
- clientId?: PubSubClientId;
1540
- /**
1541
- * The protocol being used for this session (e.g., 'sse', 'ws', 'ipc').
1542
- */
1543
- protocol: 'sse' | 'ws' | 'ipc' | string;
1544
- /**
1545
- * Sends an event and data to the client associated with this session.
1546
- * @param event The name of the event to send.
1547
- * @param data The payload for the event.
1548
- * @param ctx Optional context for the PubSub operation.
1549
- */
1550
- send: (event: string, data: any, ctx?: PubSubCtx) => void;
1551
- /**
1552
- * Closes the connection for this session.
1553
- */
1554
- close: () => void;
1555
- /**
1556
- * A reference to the raw, underlying connection object or handle
1557
- * (e.g., a Node.js `ServerResponse` for SSE, or a WebSocket instance).
1558
- * Use with caution as it is transport-specific.
1559
- */
1560
- raw?: any;
1561
- }
1562
- /**
1563
- * Defines the interface for a server-side PubSub transport layer.
1564
- *
1565
- * This abstraction allows the `EventServer` to operate independently of the
1566
- * underlying real-time communication protocol (e.g., SSE, WebSockets, IPC).
1567
- * An implementation of this interface is responsible for managing client
1568
- * connections, subscriptions, and message passing.
1569
- */
1570
- interface IPubSubServerTransport {
1571
- /**
1572
- * A unique, human-readable name for the transport (e.g., 'sse', 'websocket').
1573
- */
1574
- readonly name: string;
1575
- /**
1576
- * The protocol identifier.
1577
- */
1578
- readonly protocol: 'sse' | 'ws' | 'ipc' | string;
1579
- /**
1580
- * Connects a client, establishing a persistent communication channel.
1581
- *
1582
- * This method is designed to be generic. Transport-specific details, such as
1583
- * HTTP request/response objects, are passed inside the `options` parameter.
1584
- * For protocols like SSE, initial events can be passed to be subscribed to at connection time.
1585
- *
1586
- * @param options A container for transport-specific parameters, including optional initial events.
1587
- * @returns A `PubSubServerSession` object representing the newly connected client session.
1588
- */
1589
- connect: (options?: {
1590
- req: any;
1591
- res: any;
1592
- clientId?: PubSubClientId;
1593
- events?: string[];
1594
- [k: string]: any;
1595
- }) => PubSubServerSession;
1596
- /**
1597
- * Subscribes a client session to one or more events.
1598
- *
1599
- * Note: Not all transports may support subscribing to new events after the
1600
- * initial connection. For transports like SSE, this might be a no-op or
1601
- * throw an error.
1602
- *
1603
- * @param session The `PubSubServerSession` of the client.
1604
- * @param events An array of event names to subscribe to.
1605
- */
1606
- subscribe: (session: PubSubServerSession, events: string[]) => void;
1607
- /**
1608
- * Unsubscribes a client session from one or more events.
1609
- *
1610
- * Note: Not all transports may support unsubscribing from events after the
1611
- * initial connection. For transports like SSE, this might be a no-op or
1612
- * throw an error.
1613
- *
1614
- * @param session The `PubSubServerSession` of the client.
1615
- * @param events An array of event names to unsubscribe from.
1616
- */
1617
- unsubscribe: (session: PubSubServerSession, events: string[]) => void;
1618
- /**
1619
- * Publishes an event from the server to connected clients.
1620
- *
1621
- * The transport implementation should handle broadcasting to all relevant
1622
- * clients or targeting specific clients based on the `target` parameter.
1623
- *
1624
- * @param event The name of the event to publish.
1625
- * @param data The payload for the event.
1626
- * @param target Optional. Specifies the recipient(s) of the event.
1627
- * If omitted, the event is typically broadcast to all subscribed clients.
1628
- * @param target.clientId A single `PubSubClientId` or an array of IDs to
1629
- * send the event to.
1630
- * @param ctx Optional context for the PubSub operation.
1631
- */
1632
- publish: (event: string, data: any, target?: {
1633
- clientId?: PubSubClientId | PubSubClientId[];
1634
- }, ctx?: PubSubCtx) => void;
1635
- /**
1636
- * Registers a callback to be invoked when a new client connection is established
1637
- * and a session is created.
1638
- * @param cb The callback function that receives the new `PubSubServerSession`.
1639
- */
1640
- onConnection: (cb: (session: PubSubServerSession) => void) => void;
1641
- /**
1642
- * Registers a callback to be invoked when a client disconnects.
1643
- * @param cb The callback function that receives the `PubSubServerSession` of the
1644
- * disconnected client.
1645
- */
1646
- onDisconnect: (cb: (session: PubSubServerSession) => void) => void;
1647
- /**
1648
- * Optional. Registers a callback to handle incoming messages from clients.
1649
- * This is only necessary for bidirectional transport protocols like WebSockets or IPC.
1650
- *
1651
- * @param cb The callback function that receives the session, event name, data, and context.
1652
- */
1653
- onMessage?: (cb: (session: PubSubServerSession, event: string, data: any, ctx?: PubSubCtx) => void) => void;
1654
- /**
1655
- * Optional. Finds and returns a session based on a request object.
1656
- * This is used by higher-level tools to find the correct session
1657
- * for operations like adding a subscription via a generic RPC call.
1658
- * @param req The request object (e.g., http.IncomingMessage or Electron.IpcMainEvent).
1659
- * @returns The corresponding session, or undefined if not found.
1660
- */
1661
- getSessionFromReq?: (req: any) => PubSubServerSession | undefined;
1662
- }
1663
-
1664
- interface EventClientFuncParams {
1665
- event?: string | string[];
1666
- data?: any;
1667
- act?: 'sub' | 'pub' | 'unsub' | 'init';
1668
- listener?: (...args: any[]) => void;
1669
- }
1670
- declare class EventClient extends ResClientTools {
1671
- static _pubSubTransport: IPubSubClientTransport | undefined;
1672
- static setPubSubTransport(t?: IPubSubClientTransport): void;
1673
- static get pubSubTransport(): IPubSubClientTransport;
1674
- _stream: PubSubClientStream | undefined;
1675
- _streamEvents: string[] | undefined;
1676
- _sseListeners: Record<string, (data: any, ctx?: PubSubCtx) => void>;
1677
- _forwardEvents: Set<string>;
1678
- get clientId(): string | undefined;
1679
- getEvtSource(): Promise<PubSubClientStream>;
1680
- get active(): boolean;
1681
- setActive(v: boolean): Promise<void>;
1682
- description: string;
1683
- initEventStream(events?: string | string[]): Promise<PubSubClientStream>;
1684
- esListener(evtType: string, data: any, ctx?: PubSubCtx): void;
1685
- ebListener: (this: Event, ...args: any[]) => Promise<void>;
1686
- /**
1687
- * subscribe server event
1688
- * @param events
1689
- */
1690
- subscribe(events: string | string[]): Promise<any>;
1691
- /**
1692
- * unsubscribe server event
1693
- * @param events
1694
- */
1695
- unsubscribe(events: string | string[]): Promise<any>;
1696
- /**
1697
- * forward local event(s) to server
1698
- *
1699
- * subscribe these local events to forward/publish to server
1700
- *
1701
- * Note: pls backendEventable(ClientTools or EventClient) first
1702
- * @param events
1703
- */
1704
- forwardEvent(events: string | string[]): void;
1705
- /**
1706
- * unforward local event(s) to server
1707
- *
1708
- * unsubscribe these local events not to forward/publish to server
1709
- *
1710
- * Note: pls backendEventable(ClientTools or EventClient) first
1711
- * @param events
1712
- */
1713
- unforwardEvent(events: string | string[]): void;
1714
- init(events: string | string[]): Promise<any>;
1715
- close(): void;
1716
- }
1717
- declare const eventClient: EventClient;
1718
-
1719
- interface RpcMethodsServerFuncParams extends ServerFuncParams {
1720
- act?: string;
1721
- }
1722
- interface RpcMethodsServerTool {
1723
- methods: string[];
1724
- }
1725
- declare class RpcMethodsServerTool extends ServerTools {
1726
- static SpecialRpcMethodNames?: string[];
1727
- params: FuncParams;
1728
- get SpecialRpcMethodNames(): any;
1729
- initRpcMethods(methods?: string[]): void;
1730
- constructor(name: string | Function | FuncItem, options?: FuncItem | any);
1731
- cast(key: string, value: any): any;
1732
- getMethodFromParams(params: RpcMethodsServerFuncParams): string | undefined;
1733
- castParams(params: RpcMethodsServerFuncParams): RpcMethodsServerFuncParams;
1734
- func(params: RpcMethodsServerFuncParams): any;
1735
- }
1736
- declare const RpcMethodsServerToolSchema: {
1737
- methods: {
1738
- type: string;
1739
- };
1740
- };
1741
-
1742
- interface ResServerFuncParams extends RpcMethodsServerFuncParams {
1743
- id?: string | number;
1744
- val?: any;
1745
- }
1746
- interface ResServerTools {
1747
- get?({ id }: ResServerFuncParams): any;
1748
- post?(options: ResServerFuncParams): any;
1749
- put?({ id }: ResServerFuncParams): any;
1750
- delete?({ id }: ResServerFuncParams): any;
1751
- list?(options?: ResServerFuncParams): any;
1752
- }
1753
- declare class ResServerTools extends RpcMethodsServerTool {
1754
- static SpecialRpcMethodNames: any;
1755
- action: ActionName;
1756
- params: FuncParams;
1757
- constructor(name: string | Function | FuncItem, options?: FuncItem | any);
1758
- getMethodFromParams(params: ResServerFuncParams): any;
1759
- castParams(params: RpcMethodsServerFuncParams): RpcMethodsServerFuncParams;
1760
- }
1761
-
1762
- declare const ClientEventPrefix = "client:";
1763
- interface EventServerFuncParams extends ServerFuncParams {
1764
- event?: string | string[];
1765
- data?: any;
1766
- act?: 'sub' | 'pub' | 'unsub';
1767
- clientId?: string;
1768
- }
1769
- declare class EventServer extends ResServerTools {
1770
- /**
1771
- * Controls whether the client-published events are auto-emitted on server's localBus.
1772
- * Defaults to false for security. Must be explicitly enabled for 'client:' prefixed events to be emitted.
1773
- */
1774
- static autoInjectToLocalBus: boolean;
1775
- private static _boundEbListener?;
1776
- static _pubSubTransport: IPubSubServerTransport | undefined;
1777
- static setPubSubTransport(t?: IPubSubServerTransport): void;
1778
- static get pubSubTransport(): IPubSubServerTransport | undefined;
1779
- description: string;
1780
- result: string;
1781
- depends: {
1782
- "event-bus": EventToolFunc;
1783
- };
1784
- get pubSubTransport(): IPubSubServerTransport | undefined;
1785
- static publish(event: string, data: any, target?: {
1786
- clientId?: string | string[];
1787
- }): void | undefined;
1788
- static ebListener(eventType: string, ...data: any[]): void;
1789
- static alreadyForward(event: string): true | undefined;
1790
- publishServerEvent(event: string, data: any): any;
1791
- forward(events: string | string[]): void;
1792
- unforward(events: string | string[]): void;
1793
- list({ _req, _res, event }: EventServerFuncParams): PubSubServerSession;
1794
- $sub({ event, _req }: EventServerFuncParams): {
1795
- forward: boolean;
1796
- subscribed: boolean;
1797
- event: string | string[];
1798
- clientId: any;
1799
- } | {
1800
- forward: boolean;
1801
- event: string | string[];
1802
- subscribed?: undefined;
1803
- clientId?: undefined;
1804
- };
1805
- $unsub({ event, _req }: EventServerFuncParams): {
1806
- forward: boolean;
1807
- subscribed: boolean;
1808
- event: string | string[];
1809
- clientId: any;
1810
- } | {
1811
- forward: boolean;
1812
- event: string | string[];
1813
- subscribed?: undefined;
1814
- clientId?: undefined;
1815
- };
1816
- $publish({ event: events, data, _req }: EventServerFuncParams): {
1817
- event: string[];
1818
- senderId: any;
1819
- };
1820
- isStream(params: ServerFuncParams): boolean;
1821
- }
1822
- declare const eventServer: EventServer;
1823
-
1824
- declare function registerCoreTools(): void;
1825
-
1826
- export { funcGetMeta as $, type AsyncTaskId as A, type BinarySemaphoreOptions as B, ClientToolTransport as C, DefaultAsyncSemaphoreCapacity as D, TaskAbortController as E, type Funcs as F, type TaskAbortControllers as G, type TaskPromise as H, type IPubSubServerTransport as I, CancelableAbility as J, makeToolFuncCancelable as K, type FuncParamType as L, type FuncParam as M, type FuncParams as N, type TFunc as O, type PubSubServerSession as P, type BaseFuncItem as Q, RemoteToolFuncSchema as R, ServerTools as S, ToolTransport as T, type FuncItem as U, type BaseFunc as V, type ToolFuncPackage as W, ToolFunc as X, ToolFuncSchema as Y, FuncMetaSymbol as Z, funcWithMeta as _, type AIModelNameRules as a, ClientTools as a0, type ClientFuncItem as a1, ClientToolFuncSchema as a2, type ServerFuncParams as a3, type ServerFuncItem as a4, ServerToolFuncSchema as a5, registerCoreTools as a6, EventToolFunc as a7, event as a8, SecondaryCache as a9, _lrucache as aa, createLRUCache as ab, lrucache as ac, type EventClientFuncParams as ad, EventClient as ae, eventClient as af, ClientEventPrefix as ag, type EventServerFuncParams as ah, EventServer as ai, eventServer as aj, type RpcMethodsClientFuncParams as ak, RpcMethodsClientTool as al, RpcMethodsClientToolSchema as am, type RpcMethodsServerFuncParams as an, RpcMethodsServerTool as ao, RpcMethodsServerToolSchema as ap, type ResClientFuncParams as aq, ResClientTools as ar, type ResServerFuncParams as as, ResServerTools as at, type RpcMethodHandler as au, type IClientToolTransport as av, type PubSubCtx as aw, type PubSubClientId as b, type IPubSubClientTransport as c, type PubSubClientStream as d, type IToolTransport as e, type ActionName as f, PASSING_SCORE as g, ActionNames as h, type AIModelNameRuleFn as i, type AIModelNameRule as j, type RemoteFuncItem as k, type SemaphoreIsReadyFuncType as l, type BinarySemaphoreAcquireOptions as m, type BinarySemaphoreReleaseOptions as n, type BinarySemaphoreReleaserFunc as o, type SemaphoreOptions as p, type SemaphoreTaskItem as q, BinarySemaphore as r, Semaphore as s, RateLimit as t, ToolAsyncMultiTaskBit as u, ToolAsyncCancelableBit as v, ToolAsyncPriorityBit as w, AsyncFeatureBits as x, AsyncFeatures as y, type CancelableAbilityOptions as z };