@isdk/ai-tool 0.6.0 → 0.7.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.
- package/README.cn.md +103 -237
- package/README.md +101 -186
- package/dist/chunk-LNTIQQNN.mjs +1 -0
- package/dist/chunk-VIG2GB47.mjs +1 -1
- package/dist/funcs.d.mts +1 -1
- package/dist/funcs.d.ts +1 -1
- package/dist/funcs.js +1 -1
- package/dist/funcs.mjs +1 -1
- package/dist/index-BCco-g_I.d.mts +1781 -0
- package/dist/index-BCco-g_I.d.ts +1781 -0
- package/dist/index.d.mts +1068 -9
- package/dist/index.d.ts +1068 -9
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/test/util.js +1 -1
- package/docs/api/README.md +165 -0
- package/docs/{_media → api/_media}/CONTRIBUTING.md +3 -3
- package/docs/api/_media/pubsub.md +326 -0
- package/docs/api/_media/server_client_tools.md +88 -0
- package/docs/api/_media/toolFunc.md +183 -0
- package/docs/api/_media/transport.md +137 -0
- package/docs/{classes → api/classes}/AbortError.md +139 -54
- package/docs/api/classes/AlreadyExistsError.md +431 -0
- package/docs/api/classes/BaseError.md +440 -0
- package/docs/{classes → api/classes}/BinarySemaphore.md +25 -25
- package/docs/{classes → api/classes}/CancelableAbility.md +25 -25
- package/docs/api/classes/ClientToolTransport.md +310 -0
- package/docs/{classes → api/classes}/ClientTools.md +642 -180
- package/docs/{classes → api/classes}/CommonError.md +139 -54
- package/docs/{classes → api/classes}/ConfigFile.md +54 -5
- package/docs/{classes → api/classes}/EnvPromptTemplate.md +94 -48
- package/docs/{classes → api/classes}/EventClient.md +725 -232
- package/docs/{classes → api/classes}/EventEmitter.md +12 -12
- package/docs/{classes → api/classes}/EventServer.md +658 -205
- package/docs/{classes → api/classes}/EventToolFunc.md +561 -109
- package/docs/{classes → api/classes}/FStringPromptTemplate.md +94 -48
- package/docs/{classes → api/classes}/FewShotPromptTemplate.md +100 -52
- package/docs/{classes → api/classes}/GolangPromptTemplate.md +99 -53
- package/docs/api/classes/HttpClientToolTransport.md +324 -0
- package/docs/api/classes/HttpServerToolTransport.md +324 -0
- package/docs/{classes → api/classes}/IntSet.md +12 -12
- package/docs/{classes → api/classes}/LRUCache.md +26 -26
- package/docs/api/classes/NotFoundError.md +431 -0
- package/docs/api/classes/NotImplementationError.md +431 -0
- package/docs/{classes → api/classes}/PromptExampleSelector.md +9 -9
- package/docs/{classes → api/classes}/PromptTemplate.md +91 -47
- package/docs/api/classes/ReadableStreamError.md +451 -0
- package/docs/api/classes/ResClientTools.md +2878 -0
- package/docs/api/classes/ResServerTools.md +2856 -0
- package/docs/api/classes/SSEChannel.md +272 -0
- package/docs/{classes → api/classes}/Semaphore.md +26 -26
- package/docs/api/classes/ServerToolTransport.md +323 -0
- package/docs/{classes → api/classes}/ServerTools.md +579 -120
- package/docs/{classes → api/classes}/SignalGate.md +9 -9
- package/docs/api/classes/SseClientPubSubTransport.md +92 -0
- package/docs/api/classes/SseServerPubSubTransport.md +234 -0
- package/docs/{classes → api/classes}/TaskAbortController.md +9 -9
- package/docs/api/classes/ToolFunc.md +2665 -0
- package/docs/api/classes/ToolTransport.md +143 -0
- package/docs/api/classes/YamlTypeBaseObject.md +31 -0
- package/docs/api/enumerations/AsyncFeatureBits.md +33 -0
- package/docs/api/enumerations/AsyncFeatures.md +33 -0
- package/docs/api/enumerations/ErrorCode.md +177 -0
- package/docs/api/enumerations/HashAlgorithm.md +97 -0
- package/docs/{functions → api/functions}/AIArgProcessor.md +1 -1
- package/docs/{functions → api/functions}/AIStream.md +1 -1
- package/docs/{functions → api/functions}/ChoiceArgProcessor.md +1 -1
- package/docs/api/functions/DefaultDateFormat.md +21 -0
- package/docs/{functions → api/functions}/ObjectArgsToArgsInfo.md +1 -1
- package/docs/{functions → api/functions}/RateLimit.md +1 -1
- package/docs/{functions → api/functions}/TemplateArgProcessor.md +1 -1
- package/docs/api/functions/addDate.md +71 -0
- package/docs/{functions → api/functions}/assignDirs.md +1 -1
- package/docs/{functions → api/functions}/backendEventable.md +1 -1
- package/docs/{functions → api/functions}/beforeShutdown.md +1 -1
- package/docs/api/functions/calcPerplexity.md +60 -0
- package/docs/api/functions/calcPerplexitySimple.md +42 -0
- package/docs/api/functions/canonicalize.md +33 -0
- package/docs/{functions → api/functions}/completeSentences.md +1 -1
- package/docs/{functions → api/functions}/concatText.md +1 -1
- package/docs/{functions → api/functions}/countLLMTokens.md +1 -1
- package/docs/{functions → api/functions}/countRegexMatches.md +1 -1
- package/docs/{functions → api/functions}/createAbilityInjector.md +4 -4
- package/docs/{functions → api/functions}/createCallbacksTransformer.md +1 -1
- package/docs/{functions → api/functions}/createEmptyReadableStream.md +1 -1
- package/docs/{functions → api/functions}/createEndWithRepetitionDetector.md +1 -1
- package/docs/{functions → api/functions}/createError.md +1 -1
- package/docs/{functions → api/functions}/createEventStreamTransformer.md +1 -1
- package/docs/{functions → api/functions}/createHfValueFunc.md +1 -1
- package/docs/{functions → api/functions}/createLRUCache.md +1 -1
- package/docs/{functions → api/functions}/createYamlObjectTag.md +1 -1
- package/docs/{functions → api/functions}/dateToText.md +1 -1
- package/docs/{functions → api/functions}/decodeCharset.md +1 -1
- package/docs/api/functions/defaultsWithConcat.md +74 -0
- package/docs/{functions → api/functions}/detectCharset.md +1 -1
- package/docs/{functions → api/functions}/encodeLLMTokens.md +1 -1
- package/docs/{functions → api/functions}/ensureQuoted.md +1 -1
- package/docs/{functions → api/functions}/eventable.md +1 -1
- package/docs/{functions → api/functions}/expandConfig.md +1 -1
- package/docs/{functions → api/functions}/expandEnv.md +1 -1
- package/docs/{functions → api/functions}/expandObjEnv.md +1 -1
- package/docs/{functions → api/functions}/expandPath.md +1 -1
- package/docs/api/functions/expandPathInObject.md +29 -0
- package/docs/api/functions/expandPaths.md +25 -0
- package/docs/{functions → api/functions}/extNameLevel.md +1 -1
- package/docs/{functions → api/functions}/fileIsExists.md +1 -1
- package/docs/{functions → api/functions}/filterValidFnScope.md +1 -1
- package/docs/{functions → api/functions}/findIndexNonEmptyFrom.md +1 -1
- package/docs/{functions → api/functions}/findPort.md +1 -1
- package/docs/{functions → api/functions}/formatISO.md +1 -1
- package/docs/{functions → api/functions}/formatTextWithSpace.md +1 -1
- package/docs/api/functions/funcGetMeta.md +27 -0
- package/docs/api/functions/funcWithMeta.md +41 -0
- package/docs/api/functions/genUrlParamsStr.md +27 -0
- package/docs/{functions → api/functions}/getAllEnumKeys.md +1 -1
- package/docs/{functions → api/functions}/getConfigFileNames.md +1 -1
- package/docs/{functions → api/functions}/getConfigs.md +1 -1
- package/docs/{functions → api/functions}/getEnvVairables.md +1 -1
- package/docs/{functions → api/functions}/getFileMetaInfo.md +1 -1
- package/docs/{functions → api/functions}/getHashAlgoBySize.md +1 -1
- package/docs/{functions → api/functions}/getKeysPath.md +1 -1
- package/docs/{functions → api/functions}/getLLMTokenizer.md +1 -1
- package/docs/{functions → api/functions}/getMultiLevelExtname.md +1 -1
- package/docs/{functions → api/functions}/getPackageDir.md +1 -1
- package/docs/{functions → api/functions}/getRealFilepath.md +1 -1
- package/docs/{functions → api/functions}/getResponseErrorReadableStream.md +1 -1
- package/docs/{functions → api/functions}/getXDGConfigs.md +1 -1
- package/docs/{functions → api/functions}/hasDirectoryIn.md +1 -1
- package/docs/{functions → api/functions}/hash.md +1 -1
- package/docs/{functions → api/functions}/hashFile.md +1 -1
- package/docs/api/functions/hashObject.md +25 -0
- package/docs/{functions → api/functions}/hashStream.md +1 -1
- package/docs/api/functions/initShutdown.md +15 -0
- package/docs/{functions → api/functions}/isLangUsingSpaces.md +1 -1
- package/docs/{functions → api/functions}/isListItemString.md +1 -1
- package/docs/{functions → api/functions}/isModelNameMatched.md +1 -1
- package/docs/{functions → api/functions}/isPunctuationChar.md +1 -1
- package/docs/{functions → api/functions}/isQuoted.md +1 -1
- package/docs/{functions → api/functions}/isRegExp.md +1 -1
- package/docs/{functions → api/functions}/isSameString.md +1 -1
- package/docs/{functions → api/functions}/isSectionString.md +1 -1
- package/docs/{functions → api/functions}/isSentenceEnding.md +1 -1
- package/docs/{functions → api/functions}/isSepLineString.md +1 -1
- package/docs/{functions → api/functions}/isStrWrapped.md +1 -1
- package/docs/{functions → api/functions}/isSubdirectory.md +2 -2
- package/docs/{functions → api/functions}/isTitleString.md +1 -1
- package/docs/{functions → api/functions}/isValidFilename.md +1 -1
- package/docs/{functions → api/functions}/isValidFilepath.md +1 -1
- package/docs/{functions → api/functions}/isWebStream.md +1 -1
- package/docs/api/functions/joinSplitWords.md +46 -0
- package/docs/{functions → api/functions}/jsonFilterToWhere.md +1 -1
- package/docs/{functions → api/functions}/jsonToMarkdownStr.md +9 -1
- package/docs/{functions → api/functions}/loadAIConfig.md +1 -1
- package/docs/{functions → api/functions}/loadConfig.md +1 -1
- package/docs/{functions → api/functions}/loadConfigFile.md +1 -1
- package/docs/{functions → api/functions}/loadFileFromPaths.md +1 -1
- package/docs/{functions → api/functions}/loadTextFromPaths.md +1 -1
- package/docs/{functions → api/functions}/lrucache.md +1 -1
- package/docs/{functions → api/functions}/makeToolFuncCancelable.md +1 -1
- package/docs/{functions → api/functions}/matchUrlProtocol.md +1 -1
- package/docs/{functions → api/functions}/memoize.md +1 -1
- package/docs/api/functions/mergeArray.md +57 -0
- package/docs/{functions → api/functions}/messagesToText.md +1 -1
- package/docs/api/functions/normalizePath.md +21 -0
- package/docs/{functions → api/functions}/paramsSizeToScaleStr.md +1 -1
- package/docs/{functions → api/functions}/parseCommand.md +1 -1
- package/docs/{functions → api/functions}/parseDateFormat.md +1 -1
- package/docs/{functions → api/functions}/parseISO.md +1 -1
- package/docs/{functions → api/functions}/parseJsJson.md +1 -1
- package/docs/{functions → api/functions}/parseJsJsonSimpleSync.md +1 -1
- package/docs/{functions → api/functions}/parseObjectArgInfo.md +1 -1
- package/docs/{functions → api/functions}/parseObjectArgumentInfos.md +1 -1
- package/docs/{functions → api/functions}/parseObjectArguments.md +1 -1
- package/docs/{functions → api/functions}/parseObjectArgumentsAsArgInfos.md +1 -1
- package/docs/{functions → api/functions}/parseYaml.md +1 -1
- package/docs/api/functions/pruneSubdirectories.md +35 -0
- package/docs/api/functions/pruneSubdirectoriesInPlace.md +38 -0
- package/docs/{functions → api/functions}/quoteStr.md +1 -1
- package/docs/{functions → api/functions}/readFilenamesRecursiveSync.md +1 -1
- package/docs/{functions → api/functions}/readTextFileChunks.md +1 -1
- package/docs/{functions → api/functions}/readTextFileChunksEx.md +1 -1
- package/docs/{functions → api/functions}/readableFromAsyncIterable.md +1 -1
- package/docs/{functions → api/functions}/registerCoreTools.md +1 -1
- package/docs/{functions → api/functions}/registerYamlTag.md +1 -1
- package/docs/{functions → api/functions}/removeMarkdownBold.md +1 -1
- package/docs/{functions → api/functions}/removeMarkdownBoldAndItalic.md +1 -1
- package/docs/{functions → api/functions}/removeMarkdownItalic.md +1 -1
- package/docs/{functions → api/functions}/replaceWithPlaceholder.md +1 -1
- package/docs/{functions → api/functions}/restoreFromPlacehoders.md +1 -1
- package/docs/{functions → api/functions}/sanitizeFilename.md +1 -1
- package/docs/{functions → api/functions}/sanitizeFilepath.md +1 -1
- package/docs/{functions → api/functions}/saveConfigFile.md +1 -1
- package/docs/{functions → api/functions}/scaleStrToParamsSize.md +1 -1
- package/docs/{functions → api/functions}/shutdown.md +1 -1
- package/docs/{functions → api/functions}/simplifyObjectArguments.md +1 -1
- package/docs/api/functions/sleep.md +36 -0
- package/docs/{functions → api/functions}/sortedValues.md +1 -1
- package/docs/{functions → api/functions}/splitChunks.md +1 -1
- package/docs/{functions → api/functions}/splitParagraph.md +1 -1
- package/docs/{functions → api/functions}/splitSentence.md +1 -1
- package/docs/api/functions/splitWords.md +42 -0
- package/docs/{functions → api/functions}/stringifyYaml.md +1 -1
- package/docs/{functions → api/functions}/stripConsoleColor.md +1 -1
- package/docs/{functions → api/functions}/textToDate.md +1 -1
- package/docs/{functions → api/functions}/throwError.md +3 -3
- package/docs/{functions → api/functions}/toDate.md +1 -1
- package/docs/{functions → api/functions}/toDateTime.md +1 -1
- package/docs/{functions → api/functions}/toRegExp.md +1 -1
- package/docs/{functions → api/functions}/trimStartOfStreamHelper.md +1 -1
- package/docs/{functions → api/functions}/truncTo.md +1 -1
- package/docs/{functions → api/functions}/truncateByToken.md +1 -1
- package/docs/{functions → api/functions}/truncateToTokenLimit.md +1 -1
- package/docs/{functions → api/functions}/truncateToTokenLimitEx.md +1 -1
- package/docs/{functions → api/functions}/uuid.md +1 -1
- package/docs/{functions → api/functions}/uuidParse.md +1 -1
- package/docs/{functions → api/functions}/uuidStringify.md +1 -1
- package/docs/{functions → api/functions}/uuidValidate.md +1 -1
- package/docs/{functions → api/functions}/uuidVersion.md +1 -1
- package/docs/{functions → api/functions}/uuidv1.md +9 -5
- package/docs/{functions → api/functions}/uuidv4.md +9 -5
- package/docs/{functions → api/functions}/uuidv5.md +9 -5
- package/docs/api/functions/wait.md +45 -0
- package/docs/{functions → api/functions}/wrapEventEmitter.md +1 -1
- package/docs/{functions → api/functions}/xxhash.md +1 -1
- package/docs/{functions → api/functions}/xxhash32.md +1 -1
- package/docs/{functions → api/functions}/xxhash64.md +1 -1
- package/docs/{functions → api/functions}/xxhashAsStr.md +1 -1
- package/docs/api/functions/yieldExec.md +27 -0
- package/docs/{globals.md → api/globals.md} +44 -1
- package/docs/api/interfaces/AIChatAssistantMessageParam.md +129 -0
- package/docs/api/interfaces/AIChatContentPartImage.md +29 -0
- package/docs/api/interfaces/AIChatContentPartText.md +25 -0
- package/docs/api/interfaces/AIChatMessageParamBase.md +68 -0
- package/docs/api/interfaces/AIChatMessageToolCall.md +41 -0
- package/docs/{interfaces → api/interfaces}/AIChatSystemMessageParam.md +9 -9
- package/docs/api/interfaces/AIChatToolChoiceFuncObject.md +37 -0
- package/docs/api/interfaces/AIChatToolChoiceObject.md +25 -0
- package/docs/api/interfaces/AIChatToolFunc.md +41 -0
- package/docs/api/interfaces/AIChatToolFuncParam.md +37 -0
- package/docs/api/interfaces/AIChatToolMessageParam.md +113 -0
- package/docs/api/interfaces/AIChatToolParam.md +25 -0
- package/docs/api/interfaces/AIChatToolTypeObject.md +17 -0
- package/docs/api/interfaces/AIChatUserMessageParam.md +137 -0
- package/docs/api/interfaces/AIChoiceConfig.md +65 -0
- package/docs/api/interfaces/AIResult.md +65 -0
- package/docs/{interfaces → api/interfaces}/AIStreamParser.md +2 -2
- package/docs/api/interfaces/AIStreamParserOptions.md +21 -0
- package/docs/api/interfaces/BaseFunc.md +299 -0
- package/docs/api/interfaces/BaseFuncItem.md +221 -0
- package/docs/api/interfaces/BinarySemaphoreAcquireOptions.md +25 -0
- package/docs/api/interfaces/BinarySemaphoreOptions.md +57 -0
- package/docs/api/interfaces/BinarySemaphoreReleaseOptions.md +25 -0
- package/docs/api/interfaces/BinarySemaphoreReleaserFunc.md +37 -0
- package/docs/api/interfaces/CancelableAbilityOptions.md +113 -0
- package/docs/api/interfaces/ClientFuncItem.md +326 -0
- package/docs/api/interfaces/EventClientFuncParams.md +51 -0
- package/docs/api/interfaces/EventServerFuncParams.md +73 -0
- package/docs/{interfaces → api/interfaces}/FewShotPromptTemplateOptions.md +24 -12
- package/docs/api/interfaces/FuncItem.md +281 -0
- package/docs/api/interfaces/FuncParam.md +51 -0
- package/docs/api/interfaces/FuncParams.md +28 -0
- package/docs/api/interfaces/Funcs.md +15 -0
- package/docs/api/interfaces/HashAlgoParams.md +33 -0
- package/docs/api/interfaces/IClientToolTransport.md +155 -0
- package/docs/api/interfaces/IFileMetaInfo.md +65 -0
- package/docs/api/interfaces/IPubSubClientTransport.md +70 -0
- package/docs/api/interfaces/IPubSubServerTransport.md +241 -0
- package/docs/api/interfaces/IReadTextFileChunksOptions.md +143 -0
- package/docs/api/interfaces/IServerToolTransport.md +159 -0
- package/docs/api/interfaces/IToolTransport.md +73 -0
- package/docs/api/interfaces/ITruncateToTokenLimitOptions.md +99 -0
- package/docs/api/interfaces/JsonFilter.md +13 -0
- package/docs/api/interfaces/ParseObjectArgumentOptions.md +89 -0
- package/docs/api/interfaces/ProbabilityItem.md +41 -0
- package/docs/api/interfaces/PromptExampleSelectorOptions.md +34 -0
- package/docs/{interfaces → api/interfaces}/PromptTemplateOptions.md +15 -7
- package/docs/api/interfaces/PubSubClient.md +27 -0
- package/docs/api/interfaces/PubSubClientStream.md +196 -0
- package/docs/api/interfaces/PubSubServerSession.md +103 -0
- package/docs/api/interfaces/RemoteFuncItem.md +316 -0
- package/docs/api/interfaces/ReplacePlacehoderOptions.md +41 -0
- package/docs/api/interfaces/ResClientFuncParams.md +37 -0
- package/docs/api/interfaces/ResServerFuncParams.md +73 -0
- package/docs/api/interfaces/SanitizeFilenameOptions.md +25 -0
- package/docs/api/interfaces/SectionStringOptions.md +25 -0
- package/docs/api/interfaces/SemaphoreOptions.md +89 -0
- package/docs/api/interfaces/SemaphoreTaskItem.md +73 -0
- package/docs/api/interfaces/ServerFuncItem.md +339 -0
- package/docs/api/interfaces/ServerFuncParams.md +41 -0
- package/docs/api/interfaces/SplitSentenceOptions.md +41 -0
- package/docs/{interfaces → api/interfaces}/StreamCallbacksAndOptions.md +5 -5
- package/docs/{interfaces → api/interfaces}/TaskAbortControllers.md +1 -1
- package/docs/{interfaces → api/interfaces}/TaskPromise.md +6 -6
- package/docs/api/interfaces/ToolFuncPackage.md +57 -0
- package/docs/{namespaces → api/namespaces}/EventStates/variables/ABORT.md +1 -1
- package/docs/{namespaces → api/namespaces}/EventStates/variables/CONTINUE.md +1 -1
- package/docs/{namespaces → api/namespaces}/EventStates/variables/DONE.md +1 -1
- package/docs/{namespaces → api/namespaces}/EventStates/variables/STOPPED.md +1 -1
- package/docs/{namespaces → api/namespaces}/uuidv5/variables/DNS.md +1 -1
- package/docs/{namespaces → api/namespaces}/uuidv5/variables/URL.md +1 -1
- package/docs/{type-aliases → api/type-aliases}/AIChatContentPart.md +1 -1
- package/docs/{type-aliases → api/type-aliases}/AIChatMessageParam.md +1 -1
- package/docs/{type-aliases → api/type-aliases}/AIChatRole.md +1 -1
- package/docs/{type-aliases → api/type-aliases}/AIChatToolChoiceParam.md +1 -1
- package/docs/{type-aliases → api/type-aliases}/AIMessageType.md +1 -1
- package/docs/api/type-aliases/AIModelNameRule.md +14 -0
- package/docs/api/type-aliases/AIModelNameRuleFn.md +28 -0
- package/docs/api/type-aliases/AIModelNameRules.md +13 -0
- package/docs/{type-aliases → api/type-aliases}/AITextGenerationFinishReason.md +1 -1
- package/docs/api/type-aliases/ActionName.md +13 -0
- package/docs/api/type-aliases/ArrayMergeWay.md +11 -0
- package/docs/api/type-aliases/AsyncTaskId.md +11 -0
- package/docs/{type-aliases → api/type-aliases}/BeforeShutdownListener.md +1 -1
- package/docs/{type-aliases → api/type-aliases}/EventErrorListenerFn.md +1 -1
- package/docs/{type-aliases → api/type-aliases}/EventListenerFn.md +1 -1
- package/docs/api/type-aliases/FuncParamType.md +13 -0
- package/docs/{type-aliases → api/type-aliases}/PromptExamples.md +1 -1
- package/docs/api/type-aliases/PubSubClientId.md +14 -0
- package/docs/api/type-aliases/PubSubCtx.md +37 -0
- package/docs/api/type-aliases/RpcMethodHandler.md +34 -0
- package/docs/{type-aliases → api/type-aliases}/SemaphoreIsReadyFuncType.md +1 -1
- package/docs/api/type-aliases/TFunc.md +33 -0
- package/docs/{variables → api/variables}/AIChatRoles.md +1 -1
- package/docs/{variables → api/variables}/AIMessageTypes.md +1 -1
- package/docs/{variables → api/variables}/AITextGenerationFinishReasons.md +1 -1
- package/docs/{variables → api/variables}/AbortErrorCode.md +1 -1
- package/docs/api/variables/ActionNames.md +13 -0
- package/docs/{variables → api/variables}/AlreadyExistsErrorCode.md +1 -1
- package/docs/api/variables/ArrayMergeWay.md +25 -0
- package/docs/api/variables/ArrayMergeWaySymbol.md +11 -0
- package/docs/api/variables/ClientToolFuncSchema.md +83 -0
- package/docs/{variables → api/variables}/DEFAULT_CONFIG_NAME.md +1 -1
- package/docs/{variables → api/variables}/DefaultAsyncSemaphoreCapacity.md +1 -1
- package/docs/api/variables/EventBusName.md +11 -0
- package/docs/api/variables/EventName.md +11 -0
- package/docs/{variables → api/variables}/FilenameReservedRegex.md +1 -1
- package/docs/api/variables/FuncMetaSymbol.md +15 -0
- package/docs/{variables → api/variables}/InternalErrorCode.md +1 -1
- package/docs/{variables → api/variables}/LLM_TOKENIZER_NAMES.md +1 -1
- package/docs/{variables → api/variables}/LLM_TOKENIZER_NAMES_MAP.md +1 -1
- package/docs/{variables → api/variables}/NotFoundErrorCode.md +1 -1
- package/docs/{variables → api/variables}/NotImplementedErrorCode.md +1 -1
- package/docs/api/variables/PASSING_SCORE.md +13 -0
- package/docs/api/variables/RStreamErrCode.md +11 -0
- package/docs/api/variables/RemoteToolFuncSchema.md +84 -0
- package/docs/api/variables/ResponseRStreamErrCode.md +11 -0
- package/docs/{variables → api/variables}/SHUTDOWN_SIGNALS.md +1 -1
- package/docs/{variables → api/variables}/SSEChannelAlreadyClosedErrCode.md +1 -1
- package/docs/api/variables/SecondaryCache.md +11 -0
- package/docs/api/variables/ServerToolFuncSchema.md +83 -0
- package/docs/api/variables/StrangeHumanName.md +11 -0
- package/docs/api/variables/ToolAsyncCancelableBit.md +11 -0
- package/docs/api/variables/ToolAsyncMultiTaskBit.md +11 -0
- package/docs/api/variables/ToolAsyncPriorityBit.md +11 -0
- package/docs/{variables → api/variables}/ToolFuncSchema.md +14 -1
- package/docs/{variables → api/variables}/WindowsReservedNameRegex.md +1 -1
- package/docs/api/variables/base32768.md +11 -0
- package/docs/{variables → api/variables}/defaultTemplateFormat.md +1 -1
- package/docs/api/variables/event.md +11 -0
- package/docs/api/variables/eventClient.md +11 -0
- package/docs/api/variables/eventServer.md +11 -0
- package/docs/api/variables/lrucache.md +11 -0
- package/docs/{variables → api/variables}/mimeType.md +1 -1
- package/docs/{variables → api/variables}/uuidNIL.md +1 -1
- package/docs/pubsub.md +326 -0
- package/docs/server_client_tools.md +88 -0
- package/docs/toolFunc.md +183 -0
- package/docs/transport.md +137 -0
- package/package.json +38 -40
- package/dist/chunk-OYDBRUZJ.mjs +0 -1
- package/dist/index-BkwhCK1q.d.mts +0 -899
- package/dist/index-BkwhCK1q.d.ts +0 -899
- package/docs/README.md +0 -250
- package/docs/classes/AlreadyExistsError.md +0 -346
- package/docs/classes/BaseError.md +0 -359
- package/docs/classes/NotFoundError.md +0 -346
- package/docs/classes/NotImplementationError.md +0 -346
- package/docs/classes/ReadableStreamError.md +0 -366
- package/docs/classes/ResClientTools.md +0 -2451
- package/docs/classes/ResServerTools.md +0 -2427
- package/docs/classes/SSEChannel.md +0 -270
- package/docs/classes/ToolFunc.md +0 -2201
- package/docs/classes/YamlTypeBaseObject.md +0 -31
- package/docs/enumerations/AsyncFeatureBits.md +0 -33
- package/docs/enumerations/AsyncFeatures.md +0 -33
- package/docs/enumerations/ErrorCode.md +0 -177
- package/docs/enumerations/HashAlgorithm.md +0 -97
- package/docs/functions/canonicalize.md +0 -21
- package/docs/functions/initShutdown.md +0 -15
- package/docs/functions/wait.md +0 -21
- package/docs/interfaces/AIChatAssistantMessageParam.md +0 -129
- package/docs/interfaces/AIChatContentPartImage.md +0 -29
- package/docs/interfaces/AIChatContentPartText.md +0 -25
- package/docs/interfaces/AIChatMessageParamBase.md +0 -68
- package/docs/interfaces/AIChatMessageToolCall.md +0 -41
- package/docs/interfaces/AIChatToolChoiceFuncObject.md +0 -37
- package/docs/interfaces/AIChatToolChoiceObject.md +0 -25
- package/docs/interfaces/AIChatToolFunc.md +0 -41
- package/docs/interfaces/AIChatToolFuncParam.md +0 -37
- package/docs/interfaces/AIChatToolMessageParam.md +0 -113
- package/docs/interfaces/AIChatToolParam.md +0 -25
- package/docs/interfaces/AIChatToolTypeObject.md +0 -17
- package/docs/interfaces/AIChatUserMessageParam.md +0 -137
- package/docs/interfaces/AIChoiceConfig.md +0 -65
- package/docs/interfaces/AIResult.md +0 -65
- package/docs/interfaces/AIStreamParserOptions.md +0 -21
- package/docs/interfaces/BaseFunc.md +0 -157
- package/docs/interfaces/BaseFuncItem.md +0 -101
- package/docs/interfaces/BinarySemaphoreAcquireOptions.md +0 -25
- package/docs/interfaces/BinarySemaphoreOptions.md +0 -57
- package/docs/interfaces/BinarySemaphoreReleaseOptions.md +0 -25
- package/docs/interfaces/BinarySemaphoreReleaserFunc.md +0 -37
- package/docs/interfaces/CancelableAbilityOptions.md +0 -113
- package/docs/interfaces/ClientFuncItem.md +0 -175
- package/docs/interfaces/EventClientFuncParams.md +0 -51
- package/docs/interfaces/EventServerFuncParams.md +0 -67
- package/docs/interfaces/FuncItem.md +0 -143
- package/docs/interfaces/FuncParam.md +0 -61
- package/docs/interfaces/FuncParams.md +0 -13
- package/docs/interfaces/Funcs.md +0 -13
- package/docs/interfaces/HashAlgoParams.md +0 -33
- package/docs/interfaces/IFileMetaInfo.md +0 -65
- package/docs/interfaces/IReadTextFileChunksOptions.md +0 -143
- package/docs/interfaces/ITruncateToTokenLimitOptions.md +0 -99
- package/docs/interfaces/JsonFilter.md +0 -13
- package/docs/interfaces/ParseObjectArgumentOptions.md +0 -89
- package/docs/interfaces/PromptExampleSelectorOptions.md +0 -34
- package/docs/interfaces/RemoteFuncItem.md +0 -164
- package/docs/interfaces/ReplacePlacehoderOptions.md +0 -41
- package/docs/interfaces/ResClientFuncParams.md +0 -37
- package/docs/interfaces/ResServerFuncParams.md +0 -69
- package/docs/interfaces/SanitizeFilenameOptions.md +0 -25
- package/docs/interfaces/SectionStringOptions.md +0 -25
- package/docs/interfaces/SemaphoreOptions.md +0 -89
- package/docs/interfaces/SemaphoreTaskItem.md +0 -73
- package/docs/interfaces/ServerFuncItem.md +0 -183
- package/docs/interfaces/ServerFuncParams.md +0 -35
- package/docs/interfaces/SplitSentenceOptions.md +0 -41
- package/docs/interfaces/ToolFuncPackage.md +0 -47
- package/docs/type-aliases/AIModelNameRule.md +0 -11
- package/docs/type-aliases/AIModelNameRuleFn.md +0 -21
- package/docs/type-aliases/AIModelNameRules.md +0 -11
- package/docs/type-aliases/ActionName.md +0 -11
- package/docs/type-aliases/AsyncTaskId.md +0 -11
- package/docs/type-aliases/FuncParamType.md +0 -11
- package/docs/type-aliases/TFunc.md +0 -25
- package/docs/variables/ActionNames.md +0 -11
- package/docs/variables/ClientToolFuncSchema.md +0 -101
- package/docs/variables/EventBusName.md +0 -11
- package/docs/variables/EventName.md +0 -11
- package/docs/variables/PASSING_SCORE.md +0 -11
- package/docs/variables/RStreamErrCode.md +0 -11
- package/docs/variables/RemoteToolFuncSchema.md +0 -101
- package/docs/variables/ResponseRStreamErrCode.md +0 -11
- package/docs/variables/SecondaryCache.md +0 -11
- package/docs/variables/ServerToolFuncSchema.md +0 -101
- package/docs/variables/ToolAsyncCancelableBit.md +0 -11
- package/docs/variables/ToolAsyncMultiTaskBit.md +0 -11
- package/docs/variables/ToolAsyncPriorityBit.md +0 -11
- package/docs/variables/base32768.md +0 -11
- package/docs/variables/event.md +0 -11
- package/docs/variables/eventClient.md +0 -11
- package/docs/variables/eventServer.md +0 -11
- package/docs/variables/lrucache.md +0 -11
- /package/docs/{_media → api/_media}/LICENSE-MIT +0 -0
- /package/docs/{namespaces → api/namespaces}/EventStates/README.md +0 -0
- /package/docs/{namespaces → api/namespaces}/uuidv5/README.md +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,28 +1,29 @@
|
|
|
1
1
|
import * as custom_ability from 'custom-ability';
|
|
2
2
|
export { createAbilityInjector } from 'custom-ability';
|
|
3
3
|
export { toRegExp } from 'util-ex';
|
|
4
|
-
import { A as AsyncTaskId, a as AIModelNameRules } from './index-
|
|
5
|
-
export {
|
|
4
|
+
import { A as AsyncTaskId, a as AIModelNameRules, I as IPubSubServerTransport, P as PubSubClientId, b as PubSubServerSession, c as IPubSubClientTransport, d as PubSubClientStream, e as IToolTransport, S as ServerTools, T as ToolTransport, C as ClientToolTransport, F as Funcs, f as ActionName } from './index-BCco-g_I.js';
|
|
5
|
+
export { j as AIModelNameRule, i as AIModelNameRuleFn, h as ActionNames, x as AsyncFeatureBits, y as AsyncFeatures, V as BaseFunc, Q as BaseFuncItem, r as BinarySemaphore, m as BinarySemaphoreAcquireOptions, B as BinarySemaphoreOptions, n as BinarySemaphoreReleaseOptions, o as BinarySemaphoreReleaserFunc, J as CancelableAbility, z as CancelableAbilityOptions, a1 as ClientFuncItem, a2 as ClientToolFuncSchema, a0 as ClientTools, D as DefaultAsyncSemaphoreCapacity, ae as EventClient, ad as EventClientFuncParams, ah as EventServer, ag as EventServerFuncParams, a7 as EventToolFunc, U as FuncItem, Z as FuncMetaSymbol, M as FuncParam, L as FuncParamType, N as FuncParams, ao as IClientToolTransport, g as PASSING_SCORE, aq as PubSubClient, ap as PubSubCtx, t as RateLimit, k as RemoteFuncItem, R as RemoteToolFuncSchema, aj as ResClientFuncParams, ak as ResClientTools, al as ResServerFuncParams, am as ResServerTools, an as RpcMethodHandler, a9 as SecondaryCache, s as Semaphore, l as SemaphoreIsReadyFuncType, p as SemaphoreOptions, q as SemaphoreTaskItem, a4 as ServerFuncItem, a3 as ServerFuncParams, a5 as ServerToolFuncSchema, O as TFunc, E as TaskAbortController, G as TaskAbortControllers, H as TaskPromise, v as ToolAsyncCancelableBit, u as ToolAsyncMultiTaskBit, w as ToolAsyncPriorityBit, X as ToolFunc, W as ToolFuncPackage, Y as ToolFuncSchema, aa as _lrucache, ab as createLRUCache, a8 as event, af as eventClient, ai as eventServer, $ as funcGetMeta, _ as funcWithMeta, ac as lrucache, K as makeToolFuncCancelable, a6 as registerCoreTools } from './index-BCco-g_I.js';
|
|
6
|
+
import * as _isdk_common_error from '@isdk/common-error';
|
|
6
7
|
import { BaseError } from '@isdk/common-error';
|
|
7
8
|
export { AbortError, AbortErrorCode, AlreadyExistsError, AlreadyExistsErrorCode, BaseError, CommonError, ErrorCode, InternalErrorCode, NotFoundError, NotFoundErrorCode, NotImplementationError, NotImplementedErrorCode, createError, throwError } from '@isdk/common-error';
|
|
8
9
|
import { StringTemplateOptions, StringTemplate } from '@isdk/template-engines';
|
|
9
10
|
export { EnvStringTemplate as EnvPromptTemplate, FStringTemplate as FStringPromptTemplate, GolangStringTemplate as GolangPromptTemplate, StringTemplate as PromptTemplate, StringTemplateOptions as PromptTemplateOptions, createHfValueFunc, defaultTemplateFormat, expandEnv, expandObjEnv, getEnvVairables } from '@isdk/template-engines';
|
|
10
11
|
import { Event, EventEmitter } from 'events-ex';
|
|
11
12
|
export { EventEmitter, states as EventStates, eventable, wrapEventEmitter } from 'events-ex';
|
|
13
|
+
import http, { IncomingMessage, ServerResponse } from 'http';
|
|
12
14
|
import * as _base32768 from 'base32768';
|
|
13
15
|
import { IDataType } from 'hash-wasm';
|
|
14
16
|
export { ConfigFile, FilenameReservedRegex, SanitizeFilenameOptions, WindowsReservedNameRegex, extNameLevel, getMultiLevelExtname, isValidFilename, isValidFilepath, parseYaml, registerYamlTag, sanitizeFilename, sanitizeFilepath, stringifyYaml } from '@isdk/util';
|
|
15
17
|
import * as fs from 'fs';
|
|
16
18
|
import _memoize, { Options } from 'memoizee';
|
|
17
19
|
export { f as findPort } from './find-port-qS1CZ9c-.js';
|
|
18
|
-
import { PreTrainedTokenizer } from '@
|
|
20
|
+
import { PreTrainedTokenizer } from '@huggingface/transformers';
|
|
19
21
|
export { NIL as uuidNIL, parse as uuidParse, stringify as uuidStringify, validate as uuidValidate, version as uuidVersion, v1 as uuidv1, v4 as uuidv4, v5 as uuidv5 } from 'uuid';
|
|
20
22
|
export { canonicalize } from 'json-canonicalize';
|
|
21
23
|
export { mimeType } from 'mime-type/with-db';
|
|
22
|
-
export { formatISO, parse as parseDateFormat, parseISO, toDate } from 'date-fns';
|
|
24
|
+
export { add as addDate, formatISO, parse as parseDateFormat, parseISO, toDate } from 'date-fns';
|
|
23
25
|
export { LRUCache } from 'secondary-cache';
|
|
24
26
|
import 'property-manager';
|
|
25
|
-
import 'http';
|
|
26
27
|
|
|
27
28
|
declare const AITextGenerationFinishReasons: readonly ["stop", "length", "content_filter", "tool_calls", "function_call", "abort", "error", "other", null];
|
|
28
29
|
type AITextGenerationFinishReason = typeof AITextGenerationFinishReasons[number];
|
|
@@ -46,6 +47,7 @@ interface AIResult<TValue = any, TOptions = any> {
|
|
|
46
47
|
declare const AIMessageTypes: readonly ["human", "ai", "generic", "system", "tool"];
|
|
47
48
|
type AIMessageType = typeof AIMessageTypes[number];
|
|
48
49
|
declare const AIChatRoles: readonly ["user", "assistant", "system", "tool", "tool_calls"];
|
|
50
|
+
declare const StrangeHumanName = "\u964C\u751F\u4EBA";
|
|
49
51
|
type AIChatRole = (typeof AIChatRoles[number]) & string;
|
|
50
52
|
type AIChatMessageParam = AIChatMessageParamBase | AIChatSystemMessageParam | AIChatUserMessageParam | AIChatAssistantMessageParam | AIChatToolMessageParam;
|
|
51
53
|
interface AIChatMessageParamBase {
|
|
@@ -334,7 +336,39 @@ declare function splitParagraph(value: string, options?: SplitSentenceOptions):
|
|
|
334
336
|
*/
|
|
335
337
|
declare function truncTo(n: number, dec?: number, up?: number): number;
|
|
336
338
|
|
|
337
|
-
|
|
339
|
+
/**
|
|
340
|
+
* Suspends execution for a specified number of milliseconds
|
|
341
|
+
* @param ms - The number of milliseconds to pause execution
|
|
342
|
+
* @example
|
|
343
|
+
* ```ts
|
|
344
|
+
* await sleep(500); // Pause for half a second
|
|
345
|
+
* ```
|
|
346
|
+
* @remarks
|
|
347
|
+
* This implementation uses `setTimeout` under the hood and is more precise
|
|
348
|
+
* for longer durations than `setImmediate`-based approaches
|
|
349
|
+
*/
|
|
350
|
+
declare function sleep(ms: number): Promise<void>;
|
|
351
|
+
/**
|
|
352
|
+
* @alias sleep
|
|
353
|
+
* @deprecated Use {@link sleep} for clearer intent
|
|
354
|
+
*
|
|
355
|
+
* Legacy alias maintained for backward compatibility.
|
|
356
|
+
* Prefer the more explicit `sleep` naming in new code.
|
|
357
|
+
*/
|
|
358
|
+
declare const wait: typeof sleep;
|
|
359
|
+
/**
|
|
360
|
+
* Yields execution control to the event loop, allowing pending I/O operations
|
|
361
|
+
* and scheduled tasks to run before continuing.
|
|
362
|
+
*
|
|
363
|
+
* @remarks
|
|
364
|
+
* This method creates a microtask checkpoint using `setImmediate`, which helps:
|
|
365
|
+
* - Interleave CPU-intensive work with I/O events
|
|
366
|
+
* - Prevent event loop blocking
|
|
367
|
+
* - Maintain application responsiveness
|
|
368
|
+
*
|
|
369
|
+
* Particularly useful for breaking up long synchronous operations in Node.js.
|
|
370
|
+
*/
|
|
371
|
+
declare function yieldExec(): Promise<void>;
|
|
338
372
|
|
|
339
373
|
declare const EventName = "event";
|
|
340
374
|
declare const EventBusName = "event-bus";
|
|
@@ -357,6 +391,85 @@ declare function getEventableClass(Backend: any): {
|
|
|
357
391
|
};
|
|
358
392
|
declare const backendEventable: <T extends Function | (new (...args: any[]) => any)>(targetClass?: T | undefined, options?: custom_ability.AbilityOptions) => T & typeof getEventableClass & (T extends new (...args: any[]) => any ? InstanceType<T> : T);
|
|
359
393
|
|
|
394
|
+
type Events = (string | RegExp)[];
|
|
395
|
+
/**
|
|
396
|
+
* Represents a client connected to the SSE channel.
|
|
397
|
+
*/
|
|
398
|
+
type Client = {
|
|
399
|
+
/** The incoming HTTP request from the client. */
|
|
400
|
+
req: IncomingMessage;
|
|
401
|
+
/** The server response object used to send events to the client. */
|
|
402
|
+
res: ServerResponse;
|
|
403
|
+
/** An array of event names or patterns that the client is subscribed to. */
|
|
404
|
+
events?: Events;
|
|
405
|
+
/**
|
|
406
|
+
* A unique identifier for the client.
|
|
407
|
+
* If not provided during subscription, it defaults to `remoteAddress:remotePort`.
|
|
408
|
+
*/
|
|
409
|
+
clientId?: string;
|
|
410
|
+
};
|
|
411
|
+
declare const SSEChannelAlreadyClosedErrCode = 498;
|
|
412
|
+
/**
|
|
413
|
+
* A class for creating Server-Sent Events (SSE) channels.
|
|
414
|
+
* @example
|
|
415
|
+
* const sseChannel = new SSEChannel({ pingInterval: 5000 })
|
|
416
|
+
* sseChannel.publish('Hello, world!', 'greeting')
|
|
417
|
+
*/
|
|
418
|
+
declare class SSEChannel {
|
|
419
|
+
_active: boolean;
|
|
420
|
+
clients: Set<Client>;
|
|
421
|
+
messages: Record<string, any>[];
|
|
422
|
+
nextID: number;
|
|
423
|
+
options: Record<string, any>;
|
|
424
|
+
pingTimer?: NodeJS.Timeout;
|
|
425
|
+
get active(): boolean;
|
|
426
|
+
set active(v: boolean);
|
|
427
|
+
/**
|
|
428
|
+
* Creates a new SSE channel.
|
|
429
|
+
* @param options - The options for the SSE channel.
|
|
430
|
+
*/
|
|
431
|
+
constructor(options?: Record<string, any>);
|
|
432
|
+
/**
|
|
433
|
+
* Publishes data to the channel.
|
|
434
|
+
*
|
|
435
|
+
* @param data The data to send. Can be a string or a serializable object.
|
|
436
|
+
* @param eventName Optional name for the event.
|
|
437
|
+
* @param target Optional. If provided, the message will be sent only to clients with matching `clientId`s, bypassing event subscriptions.
|
|
438
|
+
* @returns The ID of the message, or `undefined` if no message was sent.
|
|
439
|
+
* @throws An error if the channel is closed.
|
|
440
|
+
*/
|
|
441
|
+
publish(data?: string | Record<string, any>, eventName?: string, target?: {
|
|
442
|
+
clientId?: string | string[];
|
|
443
|
+
}): number | undefined;
|
|
444
|
+
/**
|
|
445
|
+
* Subscribes a client to the SSE channel.
|
|
446
|
+
*
|
|
447
|
+
* @param req The incoming HTTP request.
|
|
448
|
+
* @param res The server response.
|
|
449
|
+
* @param events An array of event names or patterns to subscribe to.
|
|
450
|
+
* @param clientId An optional unique ID for the client. If not provided, it defaults to `remoteAddress:remotePort`.
|
|
451
|
+
* @returns The newly created client object.
|
|
452
|
+
* @throws An error if the channel is closed.
|
|
453
|
+
*/
|
|
454
|
+
subscribe(req: IncomingMessage, res: ServerResponse, events?: Events, clientId?: string): Client;
|
|
455
|
+
/**
|
|
456
|
+
* Unsubscribes a client from the SSE channel.
|
|
457
|
+
* @param c - The client to unsubscribe.
|
|
458
|
+
*/
|
|
459
|
+
unsubscribe(c: Client): void;
|
|
460
|
+
clearClients(): void;
|
|
461
|
+
/**
|
|
462
|
+
* Lists the clients connected to the SSE channel grouped by IP address.
|
|
463
|
+
* @returns - Returns an object where the keys are the IP addresses and the values are the number of clients connected from each IP.
|
|
464
|
+
*/
|
|
465
|
+
listClients(): Record<string, number>;
|
|
466
|
+
/**
|
|
467
|
+
* Gets the number of clients subscribed to the SSE channel.
|
|
468
|
+
* @returns - Returns the number of clients.
|
|
469
|
+
*/
|
|
470
|
+
getSubscriberCount(): number;
|
|
471
|
+
}
|
|
472
|
+
|
|
360
473
|
declare function isWebStream(val: any): val is ReadableStream<any> | WritableStream<any>;
|
|
361
474
|
|
|
362
475
|
declare const RStreamErrCode = 600;
|
|
@@ -507,6 +620,7 @@ interface HashAlgoParams {
|
|
|
507
620
|
}
|
|
508
621
|
declare function hashStream(stream: ReadableStream, { hashAlgo, seed, outputType }?: HashAlgoParams): Promise<string | Uint8Array<ArrayBufferLike>>;
|
|
509
622
|
declare function hash(value: IDataType, { hashAlgo, seed, outputType }?: HashAlgoParams): Promise<string | Uint8Array<ArrayBufferLike>>;
|
|
623
|
+
declare function hashObject(value: any, options?: HashAlgoParams): Promise<string | Uint8Array<ArrayBufferLike>>;
|
|
510
624
|
|
|
511
625
|
/**
|
|
512
626
|
* Checks if the provided model name matches the given rule.
|
|
@@ -732,8 +846,11 @@ declare function jsonToMarkdownStr(mem: any, options?: {
|
|
|
732
846
|
visiting?: Set<any>;
|
|
733
847
|
objectTag?: string;
|
|
734
848
|
arrayTag?: string;
|
|
849
|
+
parent?: any;
|
|
850
|
+
title?: string | boolean;
|
|
735
851
|
}): string;
|
|
736
852
|
|
|
853
|
+
declare function DefaultDateFormat(format?: string): string;
|
|
737
854
|
declare function toDateTime(date: Date | string | number): Date | undefined;
|
|
738
855
|
declare function textToDate(date: string, format?: string): Date;
|
|
739
856
|
declare function dateToText(date: Date, format?: string): string;
|
|
@@ -1001,7 +1118,7 @@ declare function getPackageDir(cwd: string): string;
|
|
|
1001
1118
|
*
|
|
1002
1119
|
* @param parentDir - The directory to check as the potential parent.
|
|
1003
1120
|
* @param childDir - The directory to check as the potential child.
|
|
1004
|
-
* @returns true if `childDir` is a subdirectory of `parentDir
|
|
1121
|
+
* @returns true if `childDir` is a subdirectory of `parentDir` or same folder, otherwise false.
|
|
1005
1122
|
*
|
|
1006
1123
|
* @example
|
|
1007
1124
|
* ```typescript
|
|
@@ -1031,6 +1148,39 @@ declare function hasDirectoryIn(dir: string, dirs?: string[]): boolean | undefin
|
|
|
1031
1148
|
* @returns The updated destination array with newly assigned directories from the source.
|
|
1032
1149
|
*/
|
|
1033
1150
|
declare function assignDirs(dest: string[], src: string[]): string[];
|
|
1151
|
+
/**
|
|
1152
|
+
* Filters out subdirectories from the given array of paths, keeping only the top-level (parent) directories.
|
|
1153
|
+
*
|
|
1154
|
+
* @param paths - An array of directory paths.
|
|
1155
|
+
* @returns A new array containing only the paths that are not subdirectories of any other path in the input.
|
|
1156
|
+
*
|
|
1157
|
+
* @example
|
|
1158
|
+
* ```ts
|
|
1159
|
+
* const paths = ['/usr/local', '/usr/local/include', '/home/user/project'];
|
|
1160
|
+
* const result = pruneSubdirectories(paths);
|
|
1161
|
+
* // result: ['/usr/local', '/home/user/project']
|
|
1162
|
+
* ```
|
|
1163
|
+
*/
|
|
1164
|
+
declare function pruneSubdirectories(paths: string[]): string[];
|
|
1165
|
+
/**
|
|
1166
|
+
* Filters out subdirectories from the given array of paths in-place, keeping only the top-level (parent) directories.
|
|
1167
|
+
*
|
|
1168
|
+
* This function helps organize file paths by:
|
|
1169
|
+
* * Removing any subfolders that are completely contained within other folders
|
|
1170
|
+
* * Preserving the original order of paths you added
|
|
1171
|
+
* * Eliminating duplicate paths
|
|
1172
|
+
*
|
|
1173
|
+
* @param paths - Array of directory paths to clean (can mix different OS path formats)
|
|
1174
|
+
*
|
|
1175
|
+
* @example
|
|
1176
|
+
* ```ts
|
|
1177
|
+
* let paths = ['/usr/local', '/usr/local/include', '/home/user/project'];
|
|
1178
|
+
* pruneSubdirectoriesInPlace(paths);
|
|
1179
|
+
* // paths is now: ['/usr/local', '/home/user/project']
|
|
1180
|
+
* ```
|
|
1181
|
+
*/
|
|
1182
|
+
declare function pruneSubdirectoriesInPlace(paths: string[]): void;
|
|
1183
|
+
declare function normalizePath(inputPath: string): string;
|
|
1034
1184
|
|
|
1035
1185
|
declare function isRegExp(value: any): boolean;
|
|
1036
1186
|
|
|
@@ -1120,6 +1270,175 @@ declare function truncateToTokenLimit(content: string, options?: ITruncateToToke
|
|
|
1120
1270
|
declare function truncateToTokenLimitEx(sentences: string[], options?: ITruncateToTokenLimitOptions): Promise<string[]>;
|
|
1121
1271
|
declare function truncateByToken(content: string, options?: ITruncateToTokenLimitOptions): Promise<void>;
|
|
1122
1272
|
|
|
1273
|
+
/**
|
|
1274
|
+
Extract all optional keys from the given type.
|
|
1275
|
+
|
|
1276
|
+
This is useful when you want to create a new type that contains different type values for the optional keys only.
|
|
1277
|
+
|
|
1278
|
+
@example
|
|
1279
|
+
```
|
|
1280
|
+
import type {OptionalKeysOf, Except} from 'type-fest';
|
|
1281
|
+
|
|
1282
|
+
interface User {
|
|
1283
|
+
name: string;
|
|
1284
|
+
surname: string;
|
|
1285
|
+
|
|
1286
|
+
luckyNumber?: number;
|
|
1287
|
+
}
|
|
1288
|
+
|
|
1289
|
+
const REMOVE_FIELD = Symbol('remove field symbol');
|
|
1290
|
+
type UpdateOperation<Entity extends object> = Except<Partial<Entity>, OptionalKeysOf<Entity>> & {
|
|
1291
|
+
[Key in OptionalKeysOf<Entity>]?: Entity[Key] | typeof REMOVE_FIELD;
|
|
1292
|
+
};
|
|
1293
|
+
|
|
1294
|
+
const update1: UpdateOperation<User> = {
|
|
1295
|
+
name: 'Alice'
|
|
1296
|
+
};
|
|
1297
|
+
|
|
1298
|
+
const update2: UpdateOperation<User> = {
|
|
1299
|
+
name: 'Bob',
|
|
1300
|
+
luckyNumber: REMOVE_FIELD
|
|
1301
|
+
};
|
|
1302
|
+
```
|
|
1303
|
+
|
|
1304
|
+
@category Utilities
|
|
1305
|
+
*/
|
|
1306
|
+
type OptionalKeysOf<BaseType extends object> =
|
|
1307
|
+
BaseType extends unknown // For distributing `BaseType`
|
|
1308
|
+
? (keyof {
|
|
1309
|
+
[Key in keyof BaseType as BaseType extends Record<Key, BaseType[Key]> ? never : Key]: never
|
|
1310
|
+
}) & (keyof BaseType) // Intersect with `keyof BaseType` to ensure result of `OptionalKeysOf<BaseType>` is always assignable to `keyof BaseType`
|
|
1311
|
+
: never; // Should never happen
|
|
1312
|
+
|
|
1313
|
+
/**
|
|
1314
|
+
Extract all required keys from the given type.
|
|
1315
|
+
|
|
1316
|
+
This is useful when you want to create a new type that contains different type values for the required keys only or use the list of keys for validation purposes, etc...
|
|
1317
|
+
|
|
1318
|
+
@example
|
|
1319
|
+
```
|
|
1320
|
+
import type {RequiredKeysOf} from 'type-fest';
|
|
1321
|
+
|
|
1322
|
+
declare function createValidation<Entity extends object, Key extends RequiredKeysOf<Entity> = RequiredKeysOf<Entity>>(field: Key, validator: (value: Entity[Key]) => boolean): ValidatorFn;
|
|
1323
|
+
|
|
1324
|
+
interface User {
|
|
1325
|
+
name: string;
|
|
1326
|
+
surname: string;
|
|
1327
|
+
|
|
1328
|
+
luckyNumber?: number;
|
|
1329
|
+
}
|
|
1330
|
+
|
|
1331
|
+
const validator1 = createValidation<User>('name', value => value.length < 25);
|
|
1332
|
+
const validator2 = createValidation<User>('surname', value => value.length < 25);
|
|
1333
|
+
```
|
|
1334
|
+
|
|
1335
|
+
@category Utilities
|
|
1336
|
+
*/
|
|
1337
|
+
type RequiredKeysOf<BaseType extends object> =
|
|
1338
|
+
BaseType extends unknown // For distributing `BaseType`
|
|
1339
|
+
? Exclude<keyof BaseType, OptionalKeysOf<BaseType>>
|
|
1340
|
+
: never; // Should never happen
|
|
1341
|
+
|
|
1342
|
+
/**
|
|
1343
|
+
Returns a boolean for whether the given type is `never`.
|
|
1344
|
+
|
|
1345
|
+
@link https://github.com/microsoft/TypeScript/issues/31751#issuecomment-498526919
|
|
1346
|
+
@link https://stackoverflow.com/a/53984913/10292952
|
|
1347
|
+
@link https://www.zhenghao.io/posts/ts-never
|
|
1348
|
+
|
|
1349
|
+
Useful in type utilities, such as checking if something does not occur.
|
|
1350
|
+
|
|
1351
|
+
@example
|
|
1352
|
+
```
|
|
1353
|
+
import type {IsNever, And} from 'type-fest';
|
|
1354
|
+
|
|
1355
|
+
// https://github.com/andnp/SimplyTyped/blob/master/src/types/strings.ts
|
|
1356
|
+
type AreStringsEqual<A extends string, B extends string> =
|
|
1357
|
+
And<
|
|
1358
|
+
IsNever<Exclude<A, B>> extends true ? true : false,
|
|
1359
|
+
IsNever<Exclude<B, A>> extends true ? true : false
|
|
1360
|
+
>;
|
|
1361
|
+
|
|
1362
|
+
type EndIfEqual<I extends string, O extends string> =
|
|
1363
|
+
AreStringsEqual<I, O> extends true
|
|
1364
|
+
? never
|
|
1365
|
+
: void;
|
|
1366
|
+
|
|
1367
|
+
function endIfEqual<I extends string, O extends string>(input: I, output: O): EndIfEqual<I, O> {
|
|
1368
|
+
if (input === output) {
|
|
1369
|
+
process.exit(0);
|
|
1370
|
+
}
|
|
1371
|
+
}
|
|
1372
|
+
|
|
1373
|
+
endIfEqual('abc', 'abc');
|
|
1374
|
+
//=> never
|
|
1375
|
+
|
|
1376
|
+
endIfEqual('abc', '123');
|
|
1377
|
+
//=> void
|
|
1378
|
+
```
|
|
1379
|
+
|
|
1380
|
+
@category Type Guard
|
|
1381
|
+
@category Utilities
|
|
1382
|
+
*/
|
|
1383
|
+
type IsNever<T> = [T] extends [never] ? true : false;
|
|
1384
|
+
|
|
1385
|
+
/**
|
|
1386
|
+
An if-else-like type that resolves depending on whether the given type is `never`.
|
|
1387
|
+
|
|
1388
|
+
@see {@link IsNever}
|
|
1389
|
+
|
|
1390
|
+
@example
|
|
1391
|
+
```
|
|
1392
|
+
import type {IfNever} from 'type-fest';
|
|
1393
|
+
|
|
1394
|
+
type ShouldBeTrue = IfNever<never>;
|
|
1395
|
+
//=> true
|
|
1396
|
+
|
|
1397
|
+
type ShouldBeBar = IfNever<'not never', 'foo', 'bar'>;
|
|
1398
|
+
//=> 'bar'
|
|
1399
|
+
```
|
|
1400
|
+
|
|
1401
|
+
@category Type Guard
|
|
1402
|
+
@category Utilities
|
|
1403
|
+
*/
|
|
1404
|
+
type IfNever<T, TypeIfNever = true, TypeIfNotNever = false> = (
|
|
1405
|
+
IsNever<T> extends true ? TypeIfNever : TypeIfNotNever
|
|
1406
|
+
);
|
|
1407
|
+
|
|
1408
|
+
// Can eventually be replaced with the built-in once this library supports
|
|
1409
|
+
// TS5.4+ only. Tracked in https://github.com/sindresorhus/type-fest/issues/848
|
|
1410
|
+
type NoInfer<T> = T extends infer U ? U : never;
|
|
1411
|
+
|
|
1412
|
+
/**
|
|
1413
|
+
Returns a boolean for whether the given type is `any`.
|
|
1414
|
+
|
|
1415
|
+
@link https://stackoverflow.com/a/49928360/1490091
|
|
1416
|
+
|
|
1417
|
+
Useful in type utilities, such as disallowing `any`s to be passed to a function.
|
|
1418
|
+
|
|
1419
|
+
@example
|
|
1420
|
+
```
|
|
1421
|
+
import type {IsAny} from 'type-fest';
|
|
1422
|
+
|
|
1423
|
+
const typedObject = {a: 1, b: 2} as const;
|
|
1424
|
+
const anyObject: any = {a: 1, b: 2};
|
|
1425
|
+
|
|
1426
|
+
function get<O extends (IsAny<O> extends true ? {} : Record<string, number>), K extends keyof O = keyof O>(obj: O, key: K) {
|
|
1427
|
+
return obj[key];
|
|
1428
|
+
}
|
|
1429
|
+
|
|
1430
|
+
const typedA = get(typedObject, 'a');
|
|
1431
|
+
//=> 1
|
|
1432
|
+
|
|
1433
|
+
const anyA = get(anyObject, 'a');
|
|
1434
|
+
//=> any
|
|
1435
|
+
```
|
|
1436
|
+
|
|
1437
|
+
@category Type Guard
|
|
1438
|
+
@category Utilities
|
|
1439
|
+
*/
|
|
1440
|
+
type IsAny<T> = 0 extends 1 & NoInfer<T> ? true : false;
|
|
1441
|
+
|
|
1123
1442
|
/**
|
|
1124
1443
|
Returns a boolean for whether the two given types are equal.
|
|
1125
1444
|
|
|
@@ -1152,6 +1471,377 @@ type IsEqual<A, B> =
|
|
|
1152
1471
|
? true
|
|
1153
1472
|
: false;
|
|
1154
1473
|
|
|
1474
|
+
/**
|
|
1475
|
+
Useful to flatten the type output to improve type hints shown in editors. And also to transform an interface into a type to aide with assignability.
|
|
1476
|
+
|
|
1477
|
+
@example
|
|
1478
|
+
```
|
|
1479
|
+
import type {Simplify} from 'type-fest';
|
|
1480
|
+
|
|
1481
|
+
type PositionProps = {
|
|
1482
|
+
top: number;
|
|
1483
|
+
left: number;
|
|
1484
|
+
};
|
|
1485
|
+
|
|
1486
|
+
type SizeProps = {
|
|
1487
|
+
width: number;
|
|
1488
|
+
height: number;
|
|
1489
|
+
};
|
|
1490
|
+
|
|
1491
|
+
// In your editor, hovering over `Props` will show a flattened object with all the properties.
|
|
1492
|
+
type Props = Simplify<PositionProps & SizeProps>;
|
|
1493
|
+
```
|
|
1494
|
+
|
|
1495
|
+
Sometimes it is desired to pass a value as a function argument that has a different type. At first inspection it may seem assignable, and then you discover it is not because the `value`'s type definition was defined as an interface. In the following example, `fn` requires an argument of type `Record<string, unknown>`. If the value is defined as a literal, then it is assignable. And if the `value` is defined as type using the `Simplify` utility the value is assignable. But if the `value` is defined as an interface, it is not assignable because the interface is not sealed and elsewhere a non-string property could be added to the interface.
|
|
1496
|
+
|
|
1497
|
+
If the type definition must be an interface (perhaps it was defined in a third-party npm package), then the `value` can be defined as `const value: Simplify<SomeInterface> = ...`. Then `value` will be assignable to the `fn` argument. Or the `value` can be cast as `Simplify<SomeInterface>` if you can't re-declare the `value`.
|
|
1498
|
+
|
|
1499
|
+
@example
|
|
1500
|
+
```
|
|
1501
|
+
import type {Simplify} from 'type-fest';
|
|
1502
|
+
|
|
1503
|
+
interface SomeInterface {
|
|
1504
|
+
foo: number;
|
|
1505
|
+
bar?: string;
|
|
1506
|
+
baz: number | undefined;
|
|
1507
|
+
}
|
|
1508
|
+
|
|
1509
|
+
type SomeType = {
|
|
1510
|
+
foo: number;
|
|
1511
|
+
bar?: string;
|
|
1512
|
+
baz: number | undefined;
|
|
1513
|
+
};
|
|
1514
|
+
|
|
1515
|
+
const literal = {foo: 123, bar: 'hello', baz: 456};
|
|
1516
|
+
const someType: SomeType = literal;
|
|
1517
|
+
const someInterface: SomeInterface = literal;
|
|
1518
|
+
|
|
1519
|
+
function fn(object: Record<string, unknown>): void {}
|
|
1520
|
+
|
|
1521
|
+
fn(literal); // Good: literal object type is sealed
|
|
1522
|
+
fn(someType); // Good: type is sealed
|
|
1523
|
+
fn(someInterface); // Error: Index signature for type 'string' is missing in type 'someInterface'. Because `interface` can be re-opened
|
|
1524
|
+
fn(someInterface as Simplify<SomeInterface>); // Good: transform an `interface` into a `type`
|
|
1525
|
+
```
|
|
1526
|
+
|
|
1527
|
+
@link https://github.com/microsoft/TypeScript/issues/15300
|
|
1528
|
+
@see SimplifyDeep
|
|
1529
|
+
@category Object
|
|
1530
|
+
*/
|
|
1531
|
+
type Simplify<T> = {[KeyType in keyof T]: T[KeyType]} & {};
|
|
1532
|
+
|
|
1533
|
+
/**
|
|
1534
|
+
Omit any index signatures from the given object type, leaving only explicitly defined properties.
|
|
1535
|
+
|
|
1536
|
+
This is the counterpart of `PickIndexSignature`.
|
|
1537
|
+
|
|
1538
|
+
Use-cases:
|
|
1539
|
+
- Remove overly permissive signatures from third-party types.
|
|
1540
|
+
|
|
1541
|
+
This type was taken from this [StackOverflow answer](https://stackoverflow.com/a/68261113/420747).
|
|
1542
|
+
|
|
1543
|
+
It relies on the fact that an empty object (`{}`) is assignable to an object with just an index signature, like `Record<string, unknown>`, but not to an object with explicitly defined keys, like `Record<'foo' | 'bar', unknown>`.
|
|
1544
|
+
|
|
1545
|
+
(The actual value type, `unknown`, is irrelevant and could be any type. Only the key type matters.)
|
|
1546
|
+
|
|
1547
|
+
```
|
|
1548
|
+
const indexed: Record<string, unknown> = {}; // Allowed
|
|
1549
|
+
|
|
1550
|
+
const keyed: Record<'foo', unknown> = {}; // Error
|
|
1551
|
+
// => TS2739: Type '{}' is missing the following properties from type 'Record<"foo" | "bar", unknown>': foo, bar
|
|
1552
|
+
```
|
|
1553
|
+
|
|
1554
|
+
Instead of causing a type error like the above, you can also use a [conditional type](https://www.typescriptlang.org/docs/handbook/2/conditional-types.html) to test whether a type is assignable to another:
|
|
1555
|
+
|
|
1556
|
+
```
|
|
1557
|
+
type Indexed = {} extends Record<string, unknown>
|
|
1558
|
+
? '✅ `{}` is assignable to `Record<string, unknown>`'
|
|
1559
|
+
: '❌ `{}` is NOT assignable to `Record<string, unknown>`';
|
|
1560
|
+
// => '✅ `{}` is assignable to `Record<string, unknown>`'
|
|
1561
|
+
|
|
1562
|
+
type Keyed = {} extends Record<'foo' | 'bar', unknown>
|
|
1563
|
+
? "✅ `{}` is assignable to `Record<'foo' | 'bar', unknown>`"
|
|
1564
|
+
: "❌ `{}` is NOT assignable to `Record<'foo' | 'bar', unknown>`";
|
|
1565
|
+
// => "❌ `{}` is NOT assignable to `Record<'foo' | 'bar', unknown>`"
|
|
1566
|
+
```
|
|
1567
|
+
|
|
1568
|
+
Using a [mapped type](https://www.typescriptlang.org/docs/handbook/2/mapped-types.html#further-exploration), you can then check for each `KeyType` of `ObjectType`...
|
|
1569
|
+
|
|
1570
|
+
```
|
|
1571
|
+
import type {OmitIndexSignature} from 'type-fest';
|
|
1572
|
+
|
|
1573
|
+
type OmitIndexSignature<ObjectType> = {
|
|
1574
|
+
[KeyType in keyof ObjectType // Map each key of `ObjectType`...
|
|
1575
|
+
]: ObjectType[KeyType]; // ...to its original value, i.e. `OmitIndexSignature<Foo> == Foo`.
|
|
1576
|
+
};
|
|
1577
|
+
```
|
|
1578
|
+
|
|
1579
|
+
...whether an empty object (`{}`) would be assignable to an object with that `KeyType` (`Record<KeyType, unknown>`)...
|
|
1580
|
+
|
|
1581
|
+
```
|
|
1582
|
+
import type {OmitIndexSignature} from 'type-fest';
|
|
1583
|
+
|
|
1584
|
+
type OmitIndexSignature<ObjectType> = {
|
|
1585
|
+
[KeyType in keyof ObjectType
|
|
1586
|
+
// Is `{}` assignable to `Record<KeyType, unknown>`?
|
|
1587
|
+
as {} extends Record<KeyType, unknown>
|
|
1588
|
+
? ... // ✅ `{}` is assignable to `Record<KeyType, unknown>`
|
|
1589
|
+
: ... // ❌ `{}` is NOT assignable to `Record<KeyType, unknown>`
|
|
1590
|
+
]: ObjectType[KeyType];
|
|
1591
|
+
};
|
|
1592
|
+
```
|
|
1593
|
+
|
|
1594
|
+
If `{}` is assignable, it means that `KeyType` is an index signature and we want to remove it. If it is not assignable, `KeyType` is a "real" key and we want to keep it.
|
|
1595
|
+
|
|
1596
|
+
@example
|
|
1597
|
+
```
|
|
1598
|
+
import type {OmitIndexSignature} from 'type-fest';
|
|
1599
|
+
|
|
1600
|
+
interface Example {
|
|
1601
|
+
// These index signatures will be removed.
|
|
1602
|
+
[x: string]: any
|
|
1603
|
+
[x: number]: any
|
|
1604
|
+
[x: symbol]: any
|
|
1605
|
+
[x: `head-${string}`]: string
|
|
1606
|
+
[x: `${string}-tail`]: string
|
|
1607
|
+
[x: `head-${string}-tail`]: string
|
|
1608
|
+
[x: `${bigint}`]: string
|
|
1609
|
+
[x: `embedded-${number}`]: string
|
|
1610
|
+
|
|
1611
|
+
// These explicitly defined keys will remain.
|
|
1612
|
+
foo: 'bar';
|
|
1613
|
+
qux?: 'baz';
|
|
1614
|
+
}
|
|
1615
|
+
|
|
1616
|
+
type ExampleWithoutIndexSignatures = OmitIndexSignature<Example>;
|
|
1617
|
+
// => { foo: 'bar'; qux?: 'baz' | undefined; }
|
|
1618
|
+
```
|
|
1619
|
+
|
|
1620
|
+
@see PickIndexSignature
|
|
1621
|
+
@category Object
|
|
1622
|
+
*/
|
|
1623
|
+
type OmitIndexSignature<ObjectType> = {
|
|
1624
|
+
[KeyType in keyof ObjectType as {} extends Record<KeyType, unknown>
|
|
1625
|
+
? never
|
|
1626
|
+
: KeyType]: ObjectType[KeyType];
|
|
1627
|
+
};
|
|
1628
|
+
|
|
1629
|
+
/**
|
|
1630
|
+
Pick only index signatures from the given object type, leaving out all explicitly defined properties.
|
|
1631
|
+
|
|
1632
|
+
This is the counterpart of `OmitIndexSignature`.
|
|
1633
|
+
|
|
1634
|
+
@example
|
|
1635
|
+
```
|
|
1636
|
+
import type {PickIndexSignature} from 'type-fest';
|
|
1637
|
+
|
|
1638
|
+
declare const symbolKey: unique symbol;
|
|
1639
|
+
|
|
1640
|
+
type Example = {
|
|
1641
|
+
// These index signatures will remain.
|
|
1642
|
+
[x: string]: unknown;
|
|
1643
|
+
[x: number]: unknown;
|
|
1644
|
+
[x: symbol]: unknown;
|
|
1645
|
+
[x: `head-${string}`]: string;
|
|
1646
|
+
[x: `${string}-tail`]: string;
|
|
1647
|
+
[x: `head-${string}-tail`]: string;
|
|
1648
|
+
[x: `${bigint}`]: string;
|
|
1649
|
+
[x: `embedded-${number}`]: string;
|
|
1650
|
+
|
|
1651
|
+
// These explicitly defined keys will be removed.
|
|
1652
|
+
['kebab-case-key']: string;
|
|
1653
|
+
[symbolKey]: string;
|
|
1654
|
+
foo: 'bar';
|
|
1655
|
+
qux?: 'baz';
|
|
1656
|
+
};
|
|
1657
|
+
|
|
1658
|
+
type ExampleIndexSignature = PickIndexSignature<Example>;
|
|
1659
|
+
// {
|
|
1660
|
+
// [x: string]: unknown;
|
|
1661
|
+
// [x: number]: unknown;
|
|
1662
|
+
// [x: symbol]: unknown;
|
|
1663
|
+
// [x: `head-${string}`]: string;
|
|
1664
|
+
// [x: `${string}-tail`]: string;
|
|
1665
|
+
// [x: `head-${string}-tail`]: string;
|
|
1666
|
+
// [x: `${bigint}`]: string;
|
|
1667
|
+
// [x: `embedded-${number}`]: string;
|
|
1668
|
+
// }
|
|
1669
|
+
```
|
|
1670
|
+
|
|
1671
|
+
@see OmitIndexSignature
|
|
1672
|
+
@category Object
|
|
1673
|
+
*/
|
|
1674
|
+
type PickIndexSignature<ObjectType> = {
|
|
1675
|
+
[KeyType in keyof ObjectType as {} extends Record<KeyType, unknown>
|
|
1676
|
+
? KeyType
|
|
1677
|
+
: never]: ObjectType[KeyType];
|
|
1678
|
+
};
|
|
1679
|
+
|
|
1680
|
+
// Merges two objects without worrying about index signatures.
|
|
1681
|
+
type SimpleMerge<Destination, Source> = {
|
|
1682
|
+
[Key in keyof Destination as Key extends keyof Source ? never : Key]: Destination[Key];
|
|
1683
|
+
} & Source;
|
|
1684
|
+
|
|
1685
|
+
/**
|
|
1686
|
+
Merge two types into a new type. Keys of the second type overrides keys of the first type.
|
|
1687
|
+
|
|
1688
|
+
@example
|
|
1689
|
+
```
|
|
1690
|
+
import type {Merge} from 'type-fest';
|
|
1691
|
+
|
|
1692
|
+
interface Foo {
|
|
1693
|
+
[x: string]: unknown;
|
|
1694
|
+
[x: number]: unknown;
|
|
1695
|
+
foo: string;
|
|
1696
|
+
bar: symbol;
|
|
1697
|
+
}
|
|
1698
|
+
|
|
1699
|
+
type Bar = {
|
|
1700
|
+
[x: number]: number;
|
|
1701
|
+
[x: symbol]: unknown;
|
|
1702
|
+
bar: Date;
|
|
1703
|
+
baz: boolean;
|
|
1704
|
+
};
|
|
1705
|
+
|
|
1706
|
+
export type FooBar = Merge<Foo, Bar>;
|
|
1707
|
+
// => {
|
|
1708
|
+
// [x: string]: unknown;
|
|
1709
|
+
// [x: number]: number;
|
|
1710
|
+
// [x: symbol]: unknown;
|
|
1711
|
+
// foo: string;
|
|
1712
|
+
// bar: Date;
|
|
1713
|
+
// baz: boolean;
|
|
1714
|
+
// }
|
|
1715
|
+
```
|
|
1716
|
+
|
|
1717
|
+
@category Object
|
|
1718
|
+
*/
|
|
1719
|
+
type Merge<Destination, Source> =
|
|
1720
|
+
Simplify<
|
|
1721
|
+
SimpleMerge<PickIndexSignature<Destination>, PickIndexSignature<Source>>
|
|
1722
|
+
& SimpleMerge<OmitIndexSignature<Destination>, OmitIndexSignature<Source>>
|
|
1723
|
+
>;
|
|
1724
|
+
|
|
1725
|
+
/**
|
|
1726
|
+
An if-else-like type that resolves depending on whether the given type is `any`.
|
|
1727
|
+
|
|
1728
|
+
@see {@link IsAny}
|
|
1729
|
+
|
|
1730
|
+
@example
|
|
1731
|
+
```
|
|
1732
|
+
import type {IfAny} from 'type-fest';
|
|
1733
|
+
|
|
1734
|
+
type ShouldBeTrue = IfAny<any>;
|
|
1735
|
+
//=> true
|
|
1736
|
+
|
|
1737
|
+
type ShouldBeBar = IfAny<'not any', 'foo', 'bar'>;
|
|
1738
|
+
//=> 'bar'
|
|
1739
|
+
```
|
|
1740
|
+
|
|
1741
|
+
@category Type Guard
|
|
1742
|
+
@category Utilities
|
|
1743
|
+
*/
|
|
1744
|
+
type IfAny<T, TypeIfAny = true, TypeIfNotAny = false> = (
|
|
1745
|
+
IsAny<T> extends true ? TypeIfAny : TypeIfNotAny
|
|
1746
|
+
);
|
|
1747
|
+
|
|
1748
|
+
// Should never happen
|
|
1749
|
+
|
|
1750
|
+
/**
|
|
1751
|
+
An if-else-like type that resolves depending on whether the given type is `any` or `never`.
|
|
1752
|
+
|
|
1753
|
+
@example
|
|
1754
|
+
```
|
|
1755
|
+
// When `T` is a NOT `any` or `never` (like `string`) => Returns `IfNotAnyOrNever` branch
|
|
1756
|
+
type A = IfNotAnyOrNever<string, 'VALID', 'IS_ANY', 'IS_NEVER'>;
|
|
1757
|
+
//=> 'VALID'
|
|
1758
|
+
|
|
1759
|
+
// When `T` is `any` => Returns `IfAny` branch
|
|
1760
|
+
type B = IfNotAnyOrNever<any, 'VALID', 'IS_ANY', 'IS_NEVER'>;
|
|
1761
|
+
//=> 'IS_ANY'
|
|
1762
|
+
|
|
1763
|
+
// When `T` is `never` => Returns `IfNever` branch
|
|
1764
|
+
type C = IfNotAnyOrNever<never, 'VALID', 'IS_ANY', 'IS_NEVER'>;
|
|
1765
|
+
//=> 'IS_NEVER'
|
|
1766
|
+
```
|
|
1767
|
+
*/
|
|
1768
|
+
type IfNotAnyOrNever<T, IfNotAnyOrNever, IfAny = any, IfNever = never> =
|
|
1769
|
+
IsAny<T> extends true
|
|
1770
|
+
? IfAny
|
|
1771
|
+
: IsNever<T> extends true
|
|
1772
|
+
? IfNever
|
|
1773
|
+
: IfNotAnyOrNever;
|
|
1774
|
+
|
|
1775
|
+
/**
|
|
1776
|
+
Merges user specified options with default options.
|
|
1777
|
+
|
|
1778
|
+
@example
|
|
1779
|
+
```
|
|
1780
|
+
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
|
1781
|
+
type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: false};
|
|
1782
|
+
type SpecifiedOptions = {leavesOnly: true};
|
|
1783
|
+
|
|
1784
|
+
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
|
1785
|
+
//=> {maxRecursionDepth: 10; leavesOnly: true}
|
|
1786
|
+
```
|
|
1787
|
+
|
|
1788
|
+
@example
|
|
1789
|
+
```
|
|
1790
|
+
// Complains if default values are not provided for optional options
|
|
1791
|
+
|
|
1792
|
+
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
|
1793
|
+
type DefaultPathsOptions = {maxRecursionDepth: 10};
|
|
1794
|
+
type SpecifiedOptions = {};
|
|
1795
|
+
|
|
1796
|
+
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
|
1797
|
+
// ~~~~~~~~~~~~~~~~~~~
|
|
1798
|
+
// Property 'leavesOnly' is missing in type 'DefaultPathsOptions' but required in type '{ maxRecursionDepth: number; leavesOnly: boolean; }'.
|
|
1799
|
+
```
|
|
1800
|
+
|
|
1801
|
+
@example
|
|
1802
|
+
```
|
|
1803
|
+
// Complains if an option's default type does not conform to the expected type
|
|
1804
|
+
|
|
1805
|
+
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
|
1806
|
+
type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: 'no'};
|
|
1807
|
+
type SpecifiedOptions = {};
|
|
1808
|
+
|
|
1809
|
+
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
|
1810
|
+
// ~~~~~~~~~~~~~~~~~~~
|
|
1811
|
+
// Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.
|
|
1812
|
+
```
|
|
1813
|
+
|
|
1814
|
+
@example
|
|
1815
|
+
```
|
|
1816
|
+
// Complains if an option's specified type does not conform to the expected type
|
|
1817
|
+
|
|
1818
|
+
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
|
1819
|
+
type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: false};
|
|
1820
|
+
type SpecifiedOptions = {leavesOnly: 'yes'};
|
|
1821
|
+
|
|
1822
|
+
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
|
1823
|
+
// ~~~~~~~~~~~~~~~~
|
|
1824
|
+
// Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.
|
|
1825
|
+
```
|
|
1826
|
+
*/
|
|
1827
|
+
type ApplyDefaultOptions<
|
|
1828
|
+
Options extends object,
|
|
1829
|
+
Defaults extends Simplify<Omit<Required<Options>, RequiredKeysOf<Options>> & Partial<Record<RequiredKeysOf<Options>, never>>>,
|
|
1830
|
+
SpecifiedOptions extends Options,
|
|
1831
|
+
> =
|
|
1832
|
+
IfAny<SpecifiedOptions, Defaults,
|
|
1833
|
+
IfNever<SpecifiedOptions, Defaults,
|
|
1834
|
+
Simplify<Merge<Defaults, {
|
|
1835
|
+
[Key in keyof SpecifiedOptions
|
|
1836
|
+
as Key extends OptionalKeysOf<Options>
|
|
1837
|
+
? Extract<SpecifiedOptions[Key], undefined> extends never
|
|
1838
|
+
? Key
|
|
1839
|
+
: never
|
|
1840
|
+
: Key
|
|
1841
|
+
]: SpecifiedOptions[Key]
|
|
1842
|
+
}> & Required<Options>> // `& Required<Options>` ensures that `ApplyDefaultOptions<SomeOption, ...>` is always assignable to `Required<SomeOption>`
|
|
1843
|
+
>>;
|
|
1844
|
+
|
|
1155
1845
|
/**
|
|
1156
1846
|
Filter out keys from an object.
|
|
1157
1847
|
|
|
@@ -1192,6 +1882,10 @@ type ExceptOptions = {
|
|
|
1192
1882
|
requireExactProps?: boolean;
|
|
1193
1883
|
};
|
|
1194
1884
|
|
|
1885
|
+
type DefaultExceptOptions = {
|
|
1886
|
+
requireExactProps: false;
|
|
1887
|
+
};
|
|
1888
|
+
|
|
1195
1889
|
/**
|
|
1196
1890
|
Create a type from an object type without certain keys.
|
|
1197
1891
|
|
|
@@ -1221,11 +1915,34 @@ type FooWithoutB = Except<Foo, 'b', {requireExactProps: true}>;
|
|
|
1221
1915
|
|
|
1222
1916
|
const fooWithoutB: FooWithoutB = {a: 1, b: '2'};
|
|
1223
1917
|
//=> errors at 'b': Type 'string' is not assignable to type 'undefined'.
|
|
1918
|
+
|
|
1919
|
+
// The `Omit` utility type doesn't work when omitting specific keys from objects containing index signatures.
|
|
1920
|
+
|
|
1921
|
+
// Consider the following example:
|
|
1922
|
+
|
|
1923
|
+
type UserData = {
|
|
1924
|
+
[metadata: string]: string;
|
|
1925
|
+
email: string;
|
|
1926
|
+
name: string;
|
|
1927
|
+
role: 'admin' | 'user';
|
|
1928
|
+
};
|
|
1929
|
+
|
|
1930
|
+
// `Omit` clearly doesn't behave as expected in this case:
|
|
1931
|
+
type PostPayload = Omit<UserData, 'email'>;
|
|
1932
|
+
//=> type PostPayload = { [x: string]: string; [x: number]: string; }
|
|
1933
|
+
|
|
1934
|
+
// In situations like this, `Except` works better.
|
|
1935
|
+
// It simply removes the `email` key while preserving all the other keys.
|
|
1936
|
+
type PostPayload = Except<UserData, 'email'>;
|
|
1937
|
+
//=> type PostPayload = { [x: string]: string; name: string; role: 'admin' | 'user'; }
|
|
1224
1938
|
```
|
|
1225
1939
|
|
|
1226
1940
|
@category Object
|
|
1227
1941
|
*/
|
|
1228
|
-
type Except<ObjectType, KeysType extends keyof ObjectType, Options extends ExceptOptions = {
|
|
1942
|
+
type Except<ObjectType, KeysType extends keyof ObjectType, Options extends ExceptOptions = {}> =
|
|
1943
|
+
_Except<ObjectType, KeysType, ApplyDefaultOptions<ExceptOptions, DefaultExceptOptions, Options>>;
|
|
1944
|
+
|
|
1945
|
+
type _Except<ObjectType, KeysType extends keyof ObjectType, Options extends Required<ExceptOptions>> = {
|
|
1229
1946
|
[KeyType in keyof ObjectType as Filter<KeyType, KeysType>]: ObjectType[KeyType];
|
|
1230
1947
|
} & (Options['requireExactProps'] extends true
|
|
1231
1948
|
? Partial<Record<KeysType, never>>
|
|
@@ -1255,6 +1972,16 @@ const responder: RequireAtLeastOne<Responder, 'text' | 'json'> = {
|
|
|
1255
1972
|
type RequireAtLeastOne<
|
|
1256
1973
|
ObjectType,
|
|
1257
1974
|
KeysType extends keyof ObjectType = keyof ObjectType,
|
|
1975
|
+
> =
|
|
1976
|
+
IfNotAnyOrNever<ObjectType,
|
|
1977
|
+
IfNever<KeysType,
|
|
1978
|
+
never,
|
|
1979
|
+
_RequireAtLeastOne<ObjectType, IfAny<KeysType, keyof ObjectType, KeysType>>
|
|
1980
|
+
>>;
|
|
1981
|
+
|
|
1982
|
+
type _RequireAtLeastOne<
|
|
1983
|
+
ObjectType,
|
|
1984
|
+
KeysType extends keyof ObjectType,
|
|
1258
1985
|
> = {
|
|
1259
1986
|
// For each `Key` in `KeysType` make a mapped type:
|
|
1260
1987
|
[Key in KeysType]-?: Required<Pick<ObjectType, Key>> & // 1. Make `Key`'s type required
|
|
@@ -1334,6 +2061,8 @@ declare function getXDGConfigs(config: Config): {
|
|
|
1334
2061
|
XDG_BIN_HOME: string;
|
|
1335
2062
|
};
|
|
1336
2063
|
declare function expandPath(path: string, config?: any): any;
|
|
2064
|
+
declare function expandPaths(paths: string[], config?: any): any[];
|
|
2065
|
+
declare function expandPathInObject(obj: any, pathKeys?: string[], config?: any): void;
|
|
1337
2066
|
|
|
1338
2067
|
/**
|
|
1339
2068
|
* @callback BeforeShutdownListener
|
|
@@ -1365,4 +2094,334 @@ declare function shutdown(signalOrEvent?: string | number, exitCode?: number | s
|
|
|
1365
2094
|
declare function beforeShutdown(listener: BeforeShutdownListener): BeforeShutdownListener | undefined;
|
|
1366
2095
|
declare function initShutdown(): void;
|
|
1367
2096
|
|
|
1368
|
-
|
|
2097
|
+
interface ProbabilityItem {
|
|
2098
|
+
/**
|
|
2099
|
+
* The id of the token.
|
|
2100
|
+
*/
|
|
2101
|
+
id?: number;
|
|
2102
|
+
/**
|
|
2103
|
+
* The token string being analyzed
|
|
2104
|
+
*/
|
|
2105
|
+
token: string;
|
|
2106
|
+
/**
|
|
2107
|
+
* The natural logarithm of the probability (log probability) assigned to this token.
|
|
2108
|
+
* Using log probabilities helps prevent numerical underflow when multiplying
|
|
2109
|
+
* many small probabilities together in language model calculations.
|
|
2110
|
+
*
|
|
2111
|
+
*/
|
|
2112
|
+
probability: number;
|
|
2113
|
+
}
|
|
2114
|
+
interface CalcPerplexityExcludeOptions {
|
|
2115
|
+
controlSymbols?: boolean;
|
|
2116
|
+
punctuation?: boolean;
|
|
2117
|
+
whitespace?: boolean;
|
|
2118
|
+
stopWords?: boolean;
|
|
2119
|
+
tokens?: string[];
|
|
2120
|
+
}
|
|
2121
|
+
interface CalcPerplexityOptions {
|
|
2122
|
+
exclude?: CalcPerplexityExcludeOptions;
|
|
2123
|
+
}
|
|
2124
|
+
/**
|
|
2125
|
+
* Calculates the perplexity of a given list of probability items.
|
|
2126
|
+
* Perplexity is a measurement used in natural language processing (NLP)
|
|
2127
|
+
* to evaluate the quality of a language model. Lower perplexity indicates
|
|
2128
|
+
* better predictions made by the model.
|
|
2129
|
+
*
|
|
2130
|
+
* @param probabilities - An array of `ProbabilityItem` objects, each containing
|
|
2131
|
+
* a token and its associated probability.
|
|
2132
|
+
* @param options - Optional configuration for excluding specific types of tokens
|
|
2133
|
+
* from the calculation.
|
|
2134
|
+
* @returns The calculated perplexity value as a number.
|
|
2135
|
+
*
|
|
2136
|
+
* @example
|
|
2137
|
+
* ```typescript
|
|
2138
|
+
* const probabilities = [
|
|
2139
|
+
* { token: "hello", probability: 0.1 },
|
|
2140
|
+
* { token: "world", probability: 0.05 },
|
|
2141
|
+
* { token: "<EOS>", probability: 0.02 },
|
|
2142
|
+
* { token: ",", probability: 0.01 }
|
|
2143
|
+
* ];
|
|
2144
|
+
*
|
|
2145
|
+
* // Exclude control symbols and punctuation from the calculation
|
|
2146
|
+
* const options = {
|
|
2147
|
+
* exclude: {
|
|
2148
|
+
* controlSymbols: true,
|
|
2149
|
+
* punctuation: true
|
|
2150
|
+
* }
|
|
2151
|
+
* };
|
|
2152
|
+
*
|
|
2153
|
+
* const perplexity = calcPerplexity(probabilities, options);
|
|
2154
|
+
* console.log(perplexity); // Outputs the calculated perplexity value
|
|
2155
|
+
* ```
|
|
2156
|
+
*/
|
|
2157
|
+
declare function calcPerplexity(probabilities: ProbabilityItem[], options?: CalcPerplexityOptions): number | undefined;
|
|
2158
|
+
/**
|
|
2159
|
+
* A simplified version of the perplexity calculation function.
|
|
2160
|
+
* This function directly calculates the perplexity from an array
|
|
2161
|
+
* of `ProbabilityItem` objects without any token exclusion options.
|
|
2162
|
+
*
|
|
2163
|
+
* @param probabilities - An array of `ProbabilityItem` objects, each containing
|
|
2164
|
+
* a token and its associated probability.
|
|
2165
|
+
* @returns The calculated perplexity value as a number.
|
|
2166
|
+
*
|
|
2167
|
+
* @example
|
|
2168
|
+
* ```typescript
|
|
2169
|
+
* const probabilities = [
|
|
2170
|
+
* { token: "hello", probability: 0.1 },
|
|
2171
|
+
* { token: "world", probability: 0.05 }
|
|
2172
|
+
* ];
|
|
2173
|
+
*
|
|
2174
|
+
* const perplexity = calcPerplexitySimple(probabilities);
|
|
2175
|
+
* console.log(perplexity); // Outputs the calculated perplexity value
|
|
2176
|
+
* ```
|
|
2177
|
+
*/
|
|
2178
|
+
declare function calcPerplexitySimple(probabilities: ProbabilityItem[]): number | undefined;
|
|
2179
|
+
|
|
2180
|
+
declare const ArrayMergeWaySymbol: unique symbol;
|
|
2181
|
+
declare const ArrayMergeWay: {
|
|
2182
|
+
readonly replace: 0;
|
|
2183
|
+
readonly start: 1;
|
|
2184
|
+
readonly end: 2;
|
|
2185
|
+
};
|
|
2186
|
+
type ArrayMergeWay = typeof ArrayMergeWay[keyof typeof ArrayMergeWay];
|
|
2187
|
+
/**
|
|
2188
|
+
* Merges multiple source objects into the target object with a custom merging strategy.
|
|
2189
|
+
*
|
|
2190
|
+
* @param target The target object, whose properties will be overridden or merged by source object values.
|
|
2191
|
+
* @param source Source objects, whose properties will be merged into the target object.
|
|
2192
|
+
* @returns The merged target object.
|
|
2193
|
+
*
|
|
2194
|
+
* This function performs deep merging using the following rules:
|
|
2195
|
+
* - For non-array properties, standard deep merging is applied.
|
|
2196
|
+
* - For arrays, a custom merging strategy is used based on the first element of the target array:
|
|
2197
|
+
* - **`@inheritMerge(.start)`** or no marker: Prepend the target array to the source array. defaults to this.
|
|
2198
|
+
* - **`@inheritMerge(.end)`**: Append the source array to the end of the target array.
|
|
2199
|
+
* - **`@inheritMerge(false)`**, **`@inheritMerge(no)`**, or **`@inheritMerge(not)`**: Replace the target array with the source array.
|
|
2200
|
+
*
|
|
2201
|
+
* @example
|
|
2202
|
+
* ```typescript
|
|
2203
|
+
* // Example 1: Default behavior (.start)
|
|
2204
|
+
* const target = {
|
|
2205
|
+
* items: ['item1', 'item2']
|
|
2206
|
+
* };
|
|
2207
|
+
* const source = {
|
|
2208
|
+
* items: ['item3', 'item4']
|
|
2209
|
+
* };
|
|
2210
|
+
* console.log(defaultsWithConcat(target, source).items);
|
|
2211
|
+
* // Output: ['item3', 'item4', 'item1', 'item2']
|
|
2212
|
+
*
|
|
2213
|
+
* // Example 2: Append behavior (.end)
|
|
2214
|
+
* const target = {
|
|
2215
|
+
* items: ['@inheritMerge(.end)', 'item1', 'item2']
|
|
2216
|
+
* };
|
|
2217
|
+
* const source = {
|
|
2218
|
+
* items: ['item3', 'item4']
|
|
2219
|
+
* };
|
|
2220
|
+
* console.log(defaultsWithConcat(target, source).items);
|
|
2221
|
+
* // Output: ['item1', 'item2', 'item3', 'item4']
|
|
2222
|
+
*
|
|
2223
|
+
* // Example 3: Replace behavior (false)
|
|
2224
|
+
* const target = {
|
|
2225
|
+
* items: ['@inheritMerge(false)', 'item1', 'item2']
|
|
2226
|
+
* };
|
|
2227
|
+
* const source = {
|
|
2228
|
+
* items: ['item3', 'item4']
|
|
2229
|
+
* };
|
|
2230
|
+
* console.log(defaultsWithConcat(target, source).items);
|
|
2231
|
+
* // Output: ['item3', 'item4']
|
|
2232
|
+
* ```
|
|
2233
|
+
*/
|
|
2234
|
+
declare function defaultsWithConcat(target: any, ...source: any[]): any;
|
|
2235
|
+
/**
|
|
2236
|
+
* Merges two arrays based on a custom strategy defined by the first element of the target array.
|
|
2237
|
+
*
|
|
2238
|
+
* The first element of the target array can contain a special marker (`@inheritMerge`) to control the merging behavior:
|
|
2239
|
+
* - `@inheritMerge(false)` or `@inheritMerge(no)` or `@inheritMerge(not)`: Replace the target array with the source array.
|
|
2240
|
+
* - `@inheritMerge(.end)`: Append the source array to the end of the target array.
|
|
2241
|
+
* - `@inheritMerge(.start)` or no marker: Prepend the target array to the source array.
|
|
2242
|
+
*
|
|
2243
|
+
* @param targetArr The target array to be merged.
|
|
2244
|
+
* @param srcArr The source array to merge into the target array.
|
|
2245
|
+
* @returns The merged array based on the specified strategy.
|
|
2246
|
+
*
|
|
2247
|
+
* @example
|
|
2248
|
+
* ```typescript
|
|
2249
|
+
* // Example 1: Default behavior (.start)
|
|
2250
|
+
* const target = ['item1', 'item2'];
|
|
2251
|
+
* const source = ['item3', 'item4'];
|
|
2252
|
+
* console.log(mergeArray(target, source)); // Output: ['item3', 'item4', 'item1', 'item2']
|
|
2253
|
+
*
|
|
2254
|
+
* // Example 2: Append behavior (.end)
|
|
2255
|
+
* const target = ['@inheritMerge(.end)', 'item1', 'item2'];
|
|
2256
|
+
* const source = ['item3', 'item4'];
|
|
2257
|
+
* console.log(mergeArray(target, source)); // Output: ['item1', 'item2', 'item3', 'item4']
|
|
2258
|
+
*
|
|
2259
|
+
* // Example 3: Replace behavior (false)
|
|
2260
|
+
* const target = ['@inheritMerge(false)', 'item1', 'item2'];
|
|
2261
|
+
* const source = ['item3', 'item4'];
|
|
2262
|
+
* console.log(mergeArray(target, source)); // Output: ['item3', 'item4']
|
|
2263
|
+
* ```
|
|
2264
|
+
*/
|
|
2265
|
+
declare function mergeArray(targetArr: any[], srcArr: any[]): any[];
|
|
2266
|
+
|
|
2267
|
+
/**
|
|
2268
|
+
* Splits a string into words using splitWords rules, then joins them with a separator
|
|
2269
|
+
*
|
|
2270
|
+
* This is a convenience function that combines word splitting and joining operations.
|
|
2271
|
+
* It's useful for converting camelCase, PascalCase, or mixed-alphanumeric strings
|
|
2272
|
+
* into human-readable formats with custom separators.
|
|
2273
|
+
*
|
|
2274
|
+
* @param input - The string to process
|
|
2275
|
+
* @param separator - The separator to use when joining words (default: space)
|
|
2276
|
+
* @returns The input string with words separated by the specified delimiter
|
|
2277
|
+
*
|
|
2278
|
+
* @example
|
|
2279
|
+
* joinSplitWords("HelloWorld") // Returns "Hello World"
|
|
2280
|
+
* joinSplitWords("item1label21Good", "-") // Returns "item1-label21-Good"
|
|
2281
|
+
* joinSplitWords("HTTPRequest", "_") // Returns "HTTP_Request"
|
|
2282
|
+
* joinSplitWords("Good morning", "-") // Returns "Good-morning"
|
|
2283
|
+
*/
|
|
2284
|
+
declare function joinSplitWords(input: string, separator?: string): string;
|
|
2285
|
+
/**
|
|
2286
|
+
* Splits a string into an array of words based on case changes, digit boundaries, and spaces.
|
|
2287
|
+
*
|
|
2288
|
+
* This function identifies word boundaries using the following rules:
|
|
2289
|
+
* 1. Between a lowercase letter followed by an uppercase letter (camelCase)
|
|
2290
|
+
* 2. Between a digit and a letter (alphanumeric boundaries)
|
|
2291
|
+
* 3. Between consecutive uppercase letters when followed by a lowercase letter (acronyms)
|
|
2292
|
+
* 4. At whitespace characters
|
|
2293
|
+
*
|
|
2294
|
+
* @param input - The string to be split into words
|
|
2295
|
+
* @returns An array of words extracted from the input string
|
|
2296
|
+
*
|
|
2297
|
+
* @example
|
|
2298
|
+
* splitWords("HelloWorld") // Returns ["Hello", "World"]
|
|
2299
|
+
* splitWords("item1label21Good") // Returns ["item1", "label21", "Good"]
|
|
2300
|
+
* splitWords("HTTPRequest") // Returns ["HTTP", "Request"]
|
|
2301
|
+
* splitWords("Good morning") // Returns ["Good", "morning"]
|
|
2302
|
+
*/
|
|
2303
|
+
declare function splitWords(input: string): string[];
|
|
2304
|
+
|
|
2305
|
+
/**
|
|
2306
|
+
* Utility to serialize an object into a URL query parameter string.
|
|
2307
|
+
* @param {any} objParam - The parameter object.
|
|
2308
|
+
* @returns {string} The URL-encoded query string or an empty string.
|
|
2309
|
+
*/
|
|
2310
|
+
declare function genUrlParamsStr(objParam: any): string;
|
|
2311
|
+
|
|
2312
|
+
declare class SseServerPubSubTransport implements IPubSubServerTransport {
|
|
2313
|
+
readonly name = "sse";
|
|
2314
|
+
readonly protocol: "sse";
|
|
2315
|
+
private channel;
|
|
2316
|
+
private onConn?;
|
|
2317
|
+
private onDis?;
|
|
2318
|
+
mount?(): void;
|
|
2319
|
+
subscribe(events?: string[], options?: {
|
|
2320
|
+
req?: IncomingMessage;
|
|
2321
|
+
res?: ServerResponse;
|
|
2322
|
+
clientId?: string;
|
|
2323
|
+
}): {
|
|
2324
|
+
req: IncomingMessage;
|
|
2325
|
+
res: ServerResponse;
|
|
2326
|
+
events?: (string | RegExp)[];
|
|
2327
|
+
clientId?: string;
|
|
2328
|
+
};
|
|
2329
|
+
publish(event: string, data: any, target?: {
|
|
2330
|
+
clientId?: PubSubClientId | PubSubClientId[];
|
|
2331
|
+
}): void;
|
|
2332
|
+
onConnection(cb: (s: PubSubServerSession) => void): void;
|
|
2333
|
+
onDisconnect(cb: (s: PubSubServerSession) => void): void;
|
|
2334
|
+
}
|
|
2335
|
+
|
|
2336
|
+
declare class SseClientPubSubTransport implements IPubSubClientTransport {
|
|
2337
|
+
connect(url: string, params?: Record<string, any>): PubSubClientStream;
|
|
2338
|
+
disconnect(stream: PubSubClientStream): void;
|
|
2339
|
+
}
|
|
2340
|
+
|
|
2341
|
+
/**
|
|
2342
|
+
* Defines the public interface for a server-side transport,
|
|
2343
|
+
* responsible for exposing ServerTools to the network.
|
|
2344
|
+
*/
|
|
2345
|
+
interface IServerToolTransport extends IToolTransport {
|
|
2346
|
+
/**
|
|
2347
|
+
* Mounts the ServerTools registry, creating the necessary API routes.
|
|
2348
|
+
* @param serverTools The ServerTools class.
|
|
2349
|
+
* @param apiPrefix An optional prefix for all API routes.
|
|
2350
|
+
* @param options Additional options for the transport start.
|
|
2351
|
+
*/
|
|
2352
|
+
mount(serverTools: typeof ServerTools, apiPrefix?: string, options?: any): void;
|
|
2353
|
+
/**
|
|
2354
|
+
* Starts the transport layer, making it listen for incoming connections.
|
|
2355
|
+
* @param options Protocol-specific options (e.g., { port, host }).
|
|
2356
|
+
*/
|
|
2357
|
+
start(options?: any): Promise<any>;
|
|
2358
|
+
/**
|
|
2359
|
+
* Stops the server instance gracefully.
|
|
2360
|
+
* @param force - Optional flag to force shutdown immediately
|
|
2361
|
+
* @returns Promise<void> when server is fully stopped
|
|
2362
|
+
*/
|
|
2363
|
+
stop(force?: boolean): Promise<void>;
|
|
2364
|
+
/**
|
|
2365
|
+
* Gets the underlying raw server instance.
|
|
2366
|
+
*/
|
|
2367
|
+
getRaw?(): any;
|
|
2368
|
+
}
|
|
2369
|
+
/**
|
|
2370
|
+
* An abstract base class for server-side transport implementations.
|
|
2371
|
+
* It provides the generic tool-mounting logic.
|
|
2372
|
+
*/
|
|
2373
|
+
declare abstract class ServerToolTransport extends ToolTransport implements IServerToolTransport {
|
|
2374
|
+
apiRoot: string;
|
|
2375
|
+
Tools: typeof ServerTools;
|
|
2376
|
+
options?: any;
|
|
2377
|
+
_mount(Tools: typeof ServerTools, apiPrefix: string, options?: any): void;
|
|
2378
|
+
start(options?: any): Promise<any>;
|
|
2379
|
+
abstract addDiscoveryHandler(path: string, handler: () => any): void;
|
|
2380
|
+
abstract addRpcHandler(serverTools: typeof ServerTools, apiPrefix: string, options?: any): void;
|
|
2381
|
+
abstract _start(options?: any): Promise<any>;
|
|
2382
|
+
abstract stop(force?: boolean): Promise<void>;
|
|
2383
|
+
abstract getRaw?(): any;
|
|
2384
|
+
}
|
|
2385
|
+
|
|
2386
|
+
/**
|
|
2387
|
+
* A concrete server transport implementation using Node.js's built-in HTTP server.
|
|
2388
|
+
*/
|
|
2389
|
+
declare class HttpServerToolTransport extends ServerToolTransport {
|
|
2390
|
+
server: http.Server;
|
|
2391
|
+
private discoveryHandlerInfo;
|
|
2392
|
+
private rpcHandlerInfo;
|
|
2393
|
+
constructor(options?: http.ServerOptions);
|
|
2394
|
+
private requestListener;
|
|
2395
|
+
addDiscoveryHandler(apiPrefix: string, handler: () => any): void;
|
|
2396
|
+
addRpcHandler(serverTools: typeof ServerTools, apiPrefix: string, options?: any): void;
|
|
2397
|
+
private handleRpcRequest;
|
|
2398
|
+
private getRequestBody;
|
|
2399
|
+
_start(options: {
|
|
2400
|
+
port: number;
|
|
2401
|
+
host?: string;
|
|
2402
|
+
}): Promise<void>;
|
|
2403
|
+
stop(): Promise<void>;
|
|
2404
|
+
getRaw(): http.Server;
|
|
2405
|
+
}
|
|
2406
|
+
|
|
2407
|
+
/**
|
|
2408
|
+
* A concrete client transport implementation that uses the browser/node `fetch` API.
|
|
2409
|
+
*/
|
|
2410
|
+
declare class HttpClientToolTransport extends ClientToolTransport {
|
|
2411
|
+
/**
|
|
2412
|
+
* Connects to the server's discovery endpoint to get the list of available tools.
|
|
2413
|
+
* @returns A promise that resolves to a map of tool function metadata.
|
|
2414
|
+
*/
|
|
2415
|
+
loadApis(): Promise<Funcs>;
|
|
2416
|
+
_fetch(name: string, args?: any, act?: ActionName | string, subName?: any, fetchOptions?: any): Promise<Response>;
|
|
2417
|
+
/**
|
|
2418
|
+
* @internal
|
|
2419
|
+
* A helper to create a structured error from a failed `fetch` response.
|
|
2420
|
+
* @param res - The HTTP response.
|
|
2421
|
+
* @returns A structured error object.
|
|
2422
|
+
*/
|
|
2423
|
+
errorFrom(name: string, res: Response): Promise<_isdk_common_error.CommonError>;
|
|
2424
|
+
toObject(res: any, args?: any): Promise<any>;
|
|
2425
|
+
}
|
|
2426
|
+
|
|
2427
|
+
export { AIArgProcessor, type AIChatAssistantMessageParam, type AIChatContentPart, type AIChatContentPartImage, type AIChatContentPartText, type AIChatMessageParam, type AIChatMessageParamBase, type AIChatMessageToolCall, type AIChatRole, AIChatRoles, type AIChatSystemMessageParam, type AIChatToolChoiceFuncObject, type AIChatToolChoiceObject, type AIChatToolChoiceParam, type AIChatToolFunc, type AIChatToolFuncParam, type AIChatToolMessageParam, type AIChatToolParam, type AIChatToolTypeObject, type AIChatUserMessageParam, type AIChoiceConfig, type AIMessageType, AIMessageTypes, AIModelNameRules, type AIResult, AIStream, type AIStreamParser, type AIStreamParserOptions, type AITextGenerationFinishReason, AITextGenerationFinishReasons, ActionName, ArrayMergeWay, ArrayMergeWaySymbol, AsyncTaskId, type BeforeShutdownListener, ChoiceArgProcessor, ClientToolTransport, DEFAULT_CONFIG_NAME, DefaultDateFormat, EventBusName, type EventErrorListenerFn, type EventListenerFn, EventName, FewShotPromptTemplate, type FewShotPromptTemplateOptions, Funcs, type HashAlgoParams, HashAlgorithm, HttpClientToolTransport, HttpServerToolTransport, type IFileMetaInfo, IPubSubClientTransport, IPubSubServerTransport, type IReadTextFileChunksOptions, type IServerToolTransport, IToolTransport, type ITruncateToTokenLimitOptions, IntSet, type JsonFilter, LLM_TOKENIZER_NAMES, LLM_TOKENIZER_NAMES_MAP, ObjectArgsToArgsInfo, type ParseObjectArgumentOptions, type ProbabilityItem, PromptExampleSelector, type PromptExampleSelectorOptions, type PromptExamples, PubSubClientId, PubSubClientStream, PubSubServerSession, RStreamErrCode, ReadableStreamError, type ReplacePlacehoderOptions, ResponseRStreamErrCode, SHUTDOWN_SIGNALS, SSEChannel, SSEChannelAlreadyClosedErrCode, type SectionStringOptions, ServerToolTransport, ServerTools, SignalGate, type SplitSentenceOptions, SseClientPubSubTransport, SseServerPubSubTransport, StrangeHumanName, type StreamCallbacksAndOptions, TemplateArgProcessor, ToolTransport, YamlTypeBaseObject, assignDirs, backendEventable, base32768, beforeShutdown, calcPerplexity, calcPerplexitySimple, completeSentences, concatText, countLLMTokens, countRegexMatches, createCallbacksTransformer, createEmptyReadableStream, createEndWithRepetitionDetector, createEventStreamTransformer, createYamlObjectTag, dateToText, decodeCharset, defaultsWithConcat, detectCharset, encodeLLMTokens, ensureQuoted, expandConfig, expandPath, expandPathInObject, expandPaths, fileIsExists, filterValidFnScope, findIndexNonEmptyFrom, formatTextWithSpace, genUrlParamsStr, getAllEnumKeys, getConfigFileNames, getConfigs, getFileMetaInfo, getHashAlgoBySize, getKeysPath, getLLMTokenizer, getPackageDir, getRealFilepath, getResponseErrorReadableStream, getXDGConfigs, hasDirectoryIn, hash, hashFile, hashObject, hashStream, initShutdown, isLangUsingSpaces, isListItemString, isModelNameMatched, isPunctuationChar, isQuoted, isRegExp, isSameString, isSectionString, isSentenceEnding, isSepLineString, isStrWrapped, isSubdirectory, isTitleString, isWebStream, joinSplitWords, jsonFilterToWhere, jsonToMarkdownStr, loadAIConfig, loadConfig, loadConfigFile, loadFileFromPaths, loadTextFromPaths, matchUrlProtocol, memoize, mergeArray, messagesToText, normalizePath, paramsSizeToScaleStr, parseCommand, parseJsJson, parseJsJsonSimpleSync, parseObjectArgInfo, parseObjectArgumentInfos, parseObjectArguments, parseObjectArgumentsAsArgInfos, pruneSubdirectories, pruneSubdirectoriesInPlace, quoteStr, readFilenamesRecursiveSync, readTextFileChunks, readTextFileChunksEx, readableFromAsyncIterable, removeMarkdownBold, removeMarkdownBoldAndItalic, removeMarkdownItalic, replaceWithPlaceholder, restoreFromPlacehoders, saveConfigFile, scaleStrToParamsSize, shutdown, simplifyObjectArguments, sleep, sortedValues, splitChunks, splitParagraph, splitSentence, splitWords, stripConsoleColor, textToDate, toDateTime, trimStartOfStreamHelper, truncTo, truncateByToken, truncateToTokenLimit, truncateToTokenLimitEx, uuid, wait, xxhash, xxhash32, xxhash64, xxhashAsStr, yieldExec };
|