@isdk/ai-tool 0.5.8 → 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 +1083 -650
- package/dist/index.d.ts +1083 -650
- 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/api/classes/ConfigFile.md +218 -0
- package/docs/{classes → api/classes}/EnvPromptTemplate.md +308 -65
- 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 +309 -66
- package/docs/{classes → api/classes}/FewShotPromptTemplate.md +290 -63
- package/docs/{classes → api/classes}/GolangPromptTemplate.md +308 -65
- 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 +303 -63
- 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/api/functions/expandConfig.md +25 -0
- package/docs/{functions → api/functions}/expandEnv.md +4 -4
- package/docs/{functions → api/functions}/expandObjEnv.md +4 -4
- 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 +4 -4
- 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/api/functions/parseYaml.md +45 -0
- 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 +7 -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/api/functions/registerYamlTag.md +37 -0
- 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 +4 -4
- package/docs/{functions → api/functions}/sanitizeFilepath.md +4 -4
- 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/api/functions/stringifyYaml.md +45 -0
- 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 -24
- 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/api/interfaces/FewShotPromptTemplateOptions.md +159 -0
- 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/{interfaces → api/interfaces}/IReadTextFileChunksOptions.md +12 -12
- 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/api/interfaces/PromptTemplateOptions.md +73 -0
- 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/api/variables/defaultTemplateFormat.md +11 -0
- 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 -38
- package/dist/chunk-YVFGQB4L.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/ConfigFile.md +0 -353
- package/docs/classes/HFEnvironment.md +0 -184
- package/docs/classes/HFInterpreter.md +0 -77
- package/docs/classes/HFTemplate.md +0 -67
- package/docs/classes/HfPromptTemplate.md +0 -1158
- 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/expandConfig.md +0 -25
- package/docs/functions/filenameReservedRegex.md +0 -20
- package/docs/functions/hfParse.md +0 -24
- package/docs/functions/hfTokenize.md +0 -27
- package/docs/functions/initShutdown.md +0 -15
- package/docs/functions/interpolateEnv.md +0 -29
- package/docs/functions/interpolateFString.md +0 -29
- package/docs/functions/interpolateGolangTemplate.md +0 -35
- package/docs/functions/parseFString.md +0 -26
- package/docs/functions/parseYaml.md +0 -25
- package/docs/functions/reControlCharsRegex.md +0 -19
- package/docs/functions/registerYamlTag.md +0 -21
- package/docs/functions/stringifyYaml.md +0 -25
- 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/DotenvExpandOptions.md +0 -43
- package/docs/interfaces/DotenvExpandOutput.md +0 -25
- package/docs/interfaces/DotenvParseInput.md +0 -13
- package/docs/interfaces/DotenvParseOutput.md +0 -13
- package/docs/interfaces/DotenvPopulateInput.md +0 -13
- package/docs/interfaces/EventClientFuncParams.md +0 -51
- package/docs/interfaces/EventServerFuncParams.md +0 -67
- package/docs/interfaces/FewShotPromptTemplateOptions.md +0 -147
- 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/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/PromptTemplateOptions.md +0 -65
- 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/FStringPromptTemplateNode.md +0 -14
- package/docs/type-aliases/FuncParamType.md +0 -11
- package/docs/type-aliases/PromptTemplateType.md +0 -11
- package/docs/type-aliases/PromptType.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/HFBuiltins.md +0 -122
- package/docs/variables/PASSING_SCORE.md +0 -11
- package/docs/variables/PromptTemplateTypes.md +0 -11
- package/docs/variables/PromptTypes.md +0 -14
- 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/defaultTemplateFormat.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
|
-
import {
|
|
9
|
+
import { StringTemplateOptions, StringTemplate } from '@isdk/template-engines';
|
|
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';
|
|
9
11
|
import { Event, EventEmitter } from 'events-ex';
|
|
10
12
|
export { EventEmitter, states as EventStates, eventable, wrapEventEmitter } from 'events-ex';
|
|
13
|
+
import http, { IncomingMessage, ServerResponse } from 'http';
|
|
11
14
|
import * as _base32768 from 'base32768';
|
|
12
15
|
import { IDataType } from 'hash-wasm';
|
|
16
|
+
export { ConfigFile, FilenameReservedRegex, SanitizeFilenameOptions, WindowsReservedNameRegex, extNameLevel, getMultiLevelExtname, isValidFilename, isValidFilepath, parseYaml, registerYamlTag, sanitizeFilename, sanitizeFilepath, stringifyYaml } from '@isdk/util';
|
|
13
17
|
import * as fs from 'fs';
|
|
14
|
-
import { ParseOptions, DocumentOptions, SchemaOptions, ToJSOptions, CreateNodeOptions, ToStringOptions } from 'yaml';
|
|
15
18
|
import _memoize, { Options } from 'memoizee';
|
|
16
19
|
export { f as findPort } from './find-port-qS1CZ9c-.js';
|
|
17
|
-
import { PreTrainedTokenizer } from '@
|
|
20
|
+
import { PreTrainedTokenizer } from '@huggingface/transformers';
|
|
18
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';
|
|
19
22
|
export { canonicalize } from 'json-canonicalize';
|
|
20
23
|
export { mimeType } from 'mime-type/with-db';
|
|
21
|
-
export {
|
|
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 {
|
|
@@ -132,60 +134,6 @@ interface AIChatToolTypeObject {
|
|
|
132
134
|
}
|
|
133
135
|
declare function messagesToText(messages: AIChatMessageParamBase[]): string;
|
|
134
136
|
|
|
135
|
-
/**
|
|
136
|
-
* Prompt Type
|
|
137
|
-
* defaults to `chat`
|
|
138
|
-
*/
|
|
139
|
-
declare const PromptTypes: readonly ["chat", "char", "plan"];
|
|
140
|
-
type PromptType = typeof PromptTypes[number];
|
|
141
|
-
declare const PromptTemplateTypes: readonly ["internal", "hf", "fill"];
|
|
142
|
-
type PromptTemplateType = typeof PromptTemplateTypes[number];
|
|
143
|
-
|
|
144
|
-
declare const defaultTemplateFormat = "default";
|
|
145
|
-
interface PromptTemplateOptions {
|
|
146
|
-
template?: string;
|
|
147
|
-
data?: Record<string, any>;
|
|
148
|
-
templateFormat?: string;
|
|
149
|
-
inputVariables?: string[];
|
|
150
|
-
compiledTemplate?: any;
|
|
151
|
-
ignoreInitialize?: boolean;
|
|
152
|
-
[name: string]: any;
|
|
153
|
-
}
|
|
154
|
-
declare class PromptTemplate extends BaseFactory {
|
|
155
|
-
compiledTemplate: any;
|
|
156
|
-
template: string;
|
|
157
|
-
templateFormat: string | undefined;
|
|
158
|
-
data: Record<string, any> | undefined;
|
|
159
|
-
inputVariables: string[] | undefined;
|
|
160
|
-
static from(template?: string | PromptTemplateOptions, options?: PromptTemplateOptions): PromptTemplate;
|
|
161
|
-
static format(options: PromptTemplateOptions): Promise<string>;
|
|
162
|
-
/**
|
|
163
|
-
* If the given options.template is the template, perform formatting using that template.
|
|
164
|
-
* @param options - The options object to check for being a template and to format.
|
|
165
|
-
* @returns A Promise that resolves to the formatted result if options is a template; otherwise, no value is returned.
|
|
166
|
-
*/
|
|
167
|
-
static formatIf(options: PromptTemplateOptions): Promise<string | undefined>;
|
|
168
|
-
static isTemplate(templateOpt: PromptTemplateOptions): any;
|
|
169
|
-
/**
|
|
170
|
-
* Validate/filter the data in inputVariables
|
|
171
|
-
* @param data
|
|
172
|
-
* @returns
|
|
173
|
-
*/
|
|
174
|
-
filterData(data: Record<string, any>): Record<string, any>;
|
|
175
|
-
constructor(template?: string | PromptTemplateOptions, options?: PromptTemplateOptions);
|
|
176
|
-
_initialize(options?: PromptTemplateOptions): void;
|
|
177
|
-
initialize(options?: PromptTemplateOptions): void;
|
|
178
|
-
_format(data: Record<string, any>): string | Promise<string>;
|
|
179
|
-
format(data?: Record<string, any>): Promise<string>;
|
|
180
|
-
/**
|
|
181
|
-
* it can make sense to "partial" a prompt template - eg pass in a subset of the required values, as to create a new prompt template which expects only the remaining subset of values.
|
|
182
|
-
* @param data the partial data
|
|
183
|
-
* @returns the new partial PromptTemplate instance
|
|
184
|
-
*/
|
|
185
|
-
partial(data: Record<string, any>): PromptTemplate;
|
|
186
|
-
toJSON(options?: PromptTemplateOptions): PromptTemplateOptions;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
137
|
type PromptExamples<T = any> = Iterable<PromiseLike<T> | T> | AsyncIterable<T>;
|
|
190
138
|
interface PromptExampleSelectorOptions {
|
|
191
139
|
/**
|
|
@@ -269,394 +217,8 @@ declare class PromptExampleSelector<T = any> {
|
|
|
269
217
|
[Symbol.asyncIterator](): AsyncGenerator<Awaited<T>, void, unknown>;
|
|
270
218
|
}
|
|
271
219
|
|
|
272
|
-
/**
|
|
273
|
-
* Represents tokens that our language understands in parsing.
|
|
274
|
-
*/
|
|
275
|
-
declare const TOKEN_TYPES: Readonly<{
|
|
276
|
-
Text: "Text";
|
|
277
|
-
NumericLiteral: "NumericLiteral";
|
|
278
|
-
BooleanLiteral: "BooleanLiteral";
|
|
279
|
-
NullLiteral: "NullLiteral";
|
|
280
|
-
StringLiteral: "StringLiteral";
|
|
281
|
-
Identifier: "Identifier";
|
|
282
|
-
Equals: "Equals";
|
|
283
|
-
OpenParen: "OpenParen";
|
|
284
|
-
CloseParen: "CloseParen";
|
|
285
|
-
OpenStatement: "OpenStatement";
|
|
286
|
-
CloseStatement: "CloseStatement";
|
|
287
|
-
OpenExpression: "OpenExpression";
|
|
288
|
-
CloseExpression: "CloseExpression";
|
|
289
|
-
OpenSquareBracket: "OpenSquareBracket";
|
|
290
|
-
CloseSquareBracket: "CloseSquareBracket";
|
|
291
|
-
OpenCurlyBracket: "OpenCurlyBracket";
|
|
292
|
-
CloseCurlyBracket: "CloseCurlyBracket";
|
|
293
|
-
Comma: "Comma";
|
|
294
|
-
Dot: "Dot";
|
|
295
|
-
Colon: "Colon";
|
|
296
|
-
Pipe: "Pipe";
|
|
297
|
-
CallOperator: "CallOperator";
|
|
298
|
-
AdditiveBinaryOperator: "AdditiveBinaryOperator";
|
|
299
|
-
MultiplicativeBinaryOperator: "MultiplicativeBinaryOperator";
|
|
300
|
-
ComparisonBinaryOperator: "ComparisonBinaryOperator";
|
|
301
|
-
UnaryOperator: "UnaryOperator";
|
|
302
|
-
Set: "Set";
|
|
303
|
-
If: "If";
|
|
304
|
-
For: "For";
|
|
305
|
-
In: "In";
|
|
306
|
-
Is: "Is";
|
|
307
|
-
NotIn: "NotIn";
|
|
308
|
-
Else: "Else";
|
|
309
|
-
EndIf: "EndIf";
|
|
310
|
-
ElseIf: "ElseIf";
|
|
311
|
-
EndFor: "EndFor";
|
|
312
|
-
And: "And";
|
|
313
|
-
Or: "Or";
|
|
314
|
-
Not: "UnaryOperator";
|
|
315
|
-
Macro: "Macro";
|
|
316
|
-
EndMacro: "EndMacro";
|
|
317
|
-
}>;
|
|
318
|
-
type TokenType = keyof typeof TOKEN_TYPES;
|
|
319
|
-
/**
|
|
320
|
-
* Represents a single token in the template.
|
|
321
|
-
*/
|
|
322
|
-
declare class Token {
|
|
323
|
-
value: string;
|
|
324
|
-
type: TokenType;
|
|
325
|
-
/**
|
|
326
|
-
* Constructs a new Token.
|
|
327
|
-
* @param {string} value The raw value as seen inside the source code.
|
|
328
|
-
* @param {TokenType} type The type of token.
|
|
329
|
-
*/
|
|
330
|
-
constructor(value: string, type: TokenType);
|
|
331
|
-
}
|
|
332
|
-
interface PreprocessOptions {
|
|
333
|
-
trim_blocks?: boolean;
|
|
334
|
-
lstrip_blocks?: boolean;
|
|
335
|
-
}
|
|
336
|
-
/**
|
|
337
|
-
* Generate a list of tokens from a source string.
|
|
338
|
-
*/
|
|
339
|
-
declare function tokenize(source: string, options?: PreprocessOptions): Token[];
|
|
340
|
-
|
|
341
|
-
/**
|
|
342
|
-
* Statements do not result in a value at runtime. They contain one or more expressions internally.
|
|
343
|
-
*/
|
|
344
|
-
declare class Statement {
|
|
345
|
-
isStatement?: boolean;
|
|
346
|
-
type: string;
|
|
347
|
-
}
|
|
348
|
-
/**
|
|
349
|
-
* Defines a block which contains many statements. Each chat template corresponds to one Program.
|
|
350
|
-
*/
|
|
351
|
-
declare class Program extends Statement {
|
|
352
|
-
body: Statement[];
|
|
353
|
-
type: string;
|
|
354
|
-
constructor(body: Statement[]);
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
/**
|
|
358
|
-
* Generate the Abstract Syntax Tree (AST) from a list of tokens.
|
|
359
|
-
* Operator precedence can be found here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_precedence#table
|
|
360
|
-
*/
|
|
361
|
-
declare function parse(tokens: Token[]): Program;
|
|
362
|
-
|
|
363
|
-
type AnyRuntimeValue = NumericValue | StringValue | BooleanValue | ObjectValue | ArrayValue | FunctionValue | NullValue | UndefinedValue;
|
|
364
|
-
/**
|
|
365
|
-
* Abstract base class for all Runtime values.
|
|
366
|
-
* Should not be instantiated directly.
|
|
367
|
-
*/
|
|
368
|
-
declare abstract class RuntimeValue<T> {
|
|
369
|
-
type: string;
|
|
370
|
-
value: T;
|
|
371
|
-
/**
|
|
372
|
-
* A collection of built-in functions for this type.
|
|
373
|
-
*/
|
|
374
|
-
builtins: Map<string, AnyRuntimeValue>;
|
|
375
|
-
/**
|
|
376
|
-
* Creates a new RuntimeValue.
|
|
377
|
-
*/
|
|
378
|
-
constructor(value?: T);
|
|
379
|
-
/**
|
|
380
|
-
* Determines truthiness or falsiness of the runtime value.
|
|
381
|
-
* This function should be overridden by subclasses if it has custom truthiness criteria.
|
|
382
|
-
* @returns {BooleanValue} BooleanValue(true) if the value is truthy, BooleanValue(false) otherwise.
|
|
383
|
-
*/
|
|
384
|
-
__bool__(): BooleanValue;
|
|
385
|
-
toString(): string;
|
|
386
|
-
toJSON(): any;
|
|
387
|
-
}
|
|
388
|
-
/**
|
|
389
|
-
* Represents a numeric value at runtime.
|
|
390
|
-
*/
|
|
391
|
-
declare class NumericValue extends RuntimeValue<number> {
|
|
392
|
-
type: string;
|
|
393
|
-
}
|
|
394
|
-
/**
|
|
395
|
-
* Represents a string value at runtime.
|
|
396
|
-
*/
|
|
397
|
-
declare class StringValue extends RuntimeValue<string> {
|
|
398
|
-
type: string;
|
|
399
|
-
builtins: Map<string, AnyRuntimeValue>;
|
|
400
|
-
}
|
|
401
|
-
/**
|
|
402
|
-
* Represents a boolean value at runtime.
|
|
403
|
-
*/
|
|
404
|
-
declare class BooleanValue extends RuntimeValue<boolean> {
|
|
405
|
-
type: string;
|
|
406
|
-
}
|
|
407
|
-
/**
|
|
408
|
-
* Represents an Object value at runtime.
|
|
409
|
-
*/
|
|
410
|
-
declare class ObjectValue extends RuntimeValue<Map<string, AnyRuntimeValue>> {
|
|
411
|
-
orgValue?: Record<string, any> | undefined;
|
|
412
|
-
type: string;
|
|
413
|
-
constructor(value: Map<string, AnyRuntimeValue>, orgValue?: Record<string, any> | undefined);
|
|
414
|
-
toString(): string;
|
|
415
|
-
toJSON(): Record<string, any>;
|
|
416
|
-
/**
|
|
417
|
-
* NOTE: necessary to override since all JavaScript arrays are considered truthy,
|
|
418
|
-
* while only non-empty Python arrays are consider truthy.
|
|
419
|
-
*
|
|
420
|
-
* e.g.,
|
|
421
|
-
* - JavaScript: {} && 5 -> 5
|
|
422
|
-
* - Python: {} and 5 -> {}
|
|
423
|
-
*/
|
|
424
|
-
__bool__(): BooleanValue;
|
|
425
|
-
builtins: Map<string, AnyRuntimeValue>;
|
|
426
|
-
}
|
|
427
|
-
/**
|
|
428
|
-
* Represents an Array value at runtime.
|
|
429
|
-
*/
|
|
430
|
-
declare class ArrayValue extends RuntimeValue<AnyRuntimeValue[]> {
|
|
431
|
-
type: string;
|
|
432
|
-
builtins: Map<string, AnyRuntimeValue>;
|
|
433
|
-
/**
|
|
434
|
-
* NOTE: necessary to override since all JavaScript arrays are considered truthy,
|
|
435
|
-
* while only non-empty Python arrays are consider truthy.
|
|
436
|
-
*
|
|
437
|
-
* e.g.,
|
|
438
|
-
* - JavaScript: [] && 5 -> 5
|
|
439
|
-
* - Python: [] and 5 -> []
|
|
440
|
-
*/
|
|
441
|
-
__bool__(): BooleanValue;
|
|
442
|
-
}
|
|
443
|
-
/**
|
|
444
|
-
* Represents a Function value at runtime.
|
|
445
|
-
*/
|
|
446
|
-
declare class FunctionValue extends RuntimeValue<(args: AnyRuntimeValue[], scope: Environment) => AnyRuntimeValue> {
|
|
447
|
-
type: string;
|
|
448
|
-
}
|
|
449
|
-
/**
|
|
450
|
-
* Represents a Null value at runtime.
|
|
451
|
-
*/
|
|
452
|
-
declare class NullValue extends RuntimeValue<null> {
|
|
453
|
-
type: string;
|
|
454
|
-
}
|
|
455
|
-
/**
|
|
456
|
-
* Represents an Undefined value at runtime.
|
|
457
|
-
*/
|
|
458
|
-
declare class UndefinedValue extends RuntimeValue<undefined> {
|
|
459
|
-
type: string;
|
|
460
|
-
}
|
|
461
|
-
/**
|
|
462
|
-
* Represents the current environment (scope) at runtime.
|
|
463
|
-
*/
|
|
464
|
-
declare class Environment {
|
|
465
|
-
parent?: Environment | undefined;
|
|
466
|
-
/**
|
|
467
|
-
* The variables declared in this environment.
|
|
468
|
-
*/
|
|
469
|
-
variables: Map<string, AnyRuntimeValue>;
|
|
470
|
-
/**
|
|
471
|
-
* The tests available in this environment.
|
|
472
|
-
*/
|
|
473
|
-
tests: Map<string, (...value: AnyRuntimeValue[]) => boolean>;
|
|
474
|
-
constructor(parent?: Environment | undefined);
|
|
475
|
-
/**
|
|
476
|
-
* Set the value of a variable in the current environment.
|
|
477
|
-
*/
|
|
478
|
-
set(name: string, value: unknown): AnyRuntimeValue;
|
|
479
|
-
private declareVariable;
|
|
480
|
-
/**
|
|
481
|
-
* Set variable in the current scope.
|
|
482
|
-
* See https://jinja.palletsprojects.com/en/3.0.x/templates/#assignments for more information.
|
|
483
|
-
*/
|
|
484
|
-
setVariable(name: string, value: AnyRuntimeValue): AnyRuntimeValue;
|
|
485
|
-
/**
|
|
486
|
-
* Resolve the environment in which the variable is declared.
|
|
487
|
-
* @param {string} name The name of the variable.
|
|
488
|
-
* @returns {Environment} The environment in which the variable is declared.
|
|
489
|
-
*/
|
|
490
|
-
private resolve;
|
|
491
|
-
lookupVariable(name: string): AnyRuntimeValue;
|
|
492
|
-
}
|
|
493
|
-
declare class Interpreter {
|
|
494
|
-
global: Environment;
|
|
495
|
-
constructor(env?: Environment);
|
|
496
|
-
/**
|
|
497
|
-
* Run the program.
|
|
498
|
-
*/
|
|
499
|
-
run(program: Program): AnyRuntimeValue;
|
|
500
|
-
/**
|
|
501
|
-
* Evaluates expressions following the binary operation type.
|
|
502
|
-
*/
|
|
503
|
-
private evaluateBinaryExpression;
|
|
504
|
-
private evaluateArguments;
|
|
505
|
-
/**
|
|
506
|
-
* Evaluates expressions following the filter operation type.
|
|
507
|
-
*/
|
|
508
|
-
private evaluateFilterExpression;
|
|
509
|
-
/**
|
|
510
|
-
* Evaluates expressions following the test operation type.
|
|
511
|
-
*/
|
|
512
|
-
private evaluateTestExpression;
|
|
513
|
-
/**
|
|
514
|
-
* Evaluates expressions following the unary operation type.
|
|
515
|
-
*/
|
|
516
|
-
private evaluateUnaryExpression;
|
|
517
|
-
private evalProgram;
|
|
518
|
-
private evaluateBlock;
|
|
519
|
-
private evaluateIdentifier;
|
|
520
|
-
private evaluateCallExpression;
|
|
521
|
-
private evaluateSliceExpression;
|
|
522
|
-
private evaluateMemberExpression;
|
|
523
|
-
private evaluateSet;
|
|
524
|
-
private evaluateIf;
|
|
525
|
-
private evaluateFor;
|
|
526
|
-
/**
|
|
527
|
-
* See https://jinja.palletsprojects.com/en/3.1.x/templates/#macros for more information.
|
|
528
|
-
*/
|
|
529
|
-
private evaluateMacro;
|
|
530
|
-
evaluate(statement: Statement | undefined, environment: Environment): AnyRuntimeValue;
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
declare function randomInt(to: number, from?: number): number;
|
|
534
|
-
/**
|
|
535
|
-
* Selects an element from the given object, array, or string.
|
|
536
|
-
* @param obj Can be an object, array, or string to select from.
|
|
537
|
-
* @param index Optional, specifies the index or key to select. Negative values indicate indices from the end.
|
|
538
|
-
* @returns The selected element, or `undefined` if the input is empty or not provided.
|
|
539
|
-
*
|
|
540
|
-
* @example
|
|
541
|
-
* // Selecting an element from an array
|
|
542
|
-
* const array = ['apple', 'banana', 'cherry']
|
|
543
|
-
* console.log(select(array)) // Random element from the array
|
|
544
|
-
* console.log(select(array, 1)) // Second element
|
|
545
|
-
* console.log(select(array, -1)) // Last element
|
|
546
|
-
*
|
|
547
|
-
* @example
|
|
548
|
-
* // Selecting a property from an object
|
|
549
|
-
* const obj = { fruit1: 'apple', fruit2: 'banana', fruit3: 'cherry' }
|
|
550
|
-
* console.log(select(obj)) // Random property from the object
|
|
551
|
-
* console.log(select(obj, 'fruit2')) // Property with key 'fruit2'
|
|
552
|
-
*
|
|
553
|
-
* @example
|
|
554
|
-
* // Selecting a character from a string
|
|
555
|
-
* const str = 'hello'
|
|
556
|
-
* console.log(select(str)) // Random character from the string
|
|
557
|
-
* console.log(select(str, 1)) // Second character
|
|
558
|
-
* console.log(select(str, -1)) // Last character
|
|
559
|
-
*/
|
|
560
|
-
declare function select(obj: any | any[], index?: number | string): any;
|
|
561
|
-
declare function tojson(value: any, indent?: number | {
|
|
562
|
-
indent?: number;
|
|
563
|
-
depth?: number;
|
|
564
|
-
}, depth?: number): string;
|
|
565
|
-
declare function join(value: any, separator?: string): any;
|
|
566
|
-
declare const builtins: {
|
|
567
|
-
randomInt: typeof randomInt;
|
|
568
|
-
select: typeof select;
|
|
569
|
-
tojson: typeof tojson;
|
|
570
|
-
join: typeof join;
|
|
571
|
-
};
|
|
572
|
-
|
|
573
|
-
/**
|
|
574
|
-
* @file Jinja templating engine
|
|
575
|
-
*
|
|
576
|
-
* A minimalistic JavaScript reimplementation of the [Jinja](https://github.com/pallets/jinja) templating engine,
|
|
577
|
-
* to support the chat templates. Special thanks to [Tyler Laceby](https://github.com/tlaceby) for his amazing
|
|
578
|
-
* ["Guide to Interpreters"](https://github.com/tlaceby/guide-to-interpreters-series) tutorial series,
|
|
579
|
-
* which provided the basis for this implementation.
|
|
580
|
-
*
|
|
581
|
-
* See the [Transformers documentation](https://huggingface.co/docs/transformers/main/en/chat_templating) for more information.
|
|
582
|
-
*
|
|
583
|
-
* @module index
|
|
584
|
-
*/
|
|
585
|
-
|
|
586
|
-
declare class EnvironmentEx extends Environment {
|
|
587
|
-
parent?: EnvironmentEx | undefined;
|
|
588
|
-
constructor(parent?: EnvironmentEx | undefined);
|
|
589
|
-
assign(items: Record<string, unknown>): void;
|
|
590
|
-
clear(): void;
|
|
591
|
-
}
|
|
592
|
-
declare class Template {
|
|
593
|
-
parsed: Program;
|
|
594
|
-
static global: EnvironmentEx;
|
|
595
|
-
/**
|
|
596
|
-
* @param {string} template The template string
|
|
597
|
-
*/
|
|
598
|
-
constructor(template: string, options?: PreprocessOptions);
|
|
599
|
-
render(items?: Record<string, unknown>): string;
|
|
600
|
-
}
|
|
601
|
-
|
|
602
|
-
declare class HfPromptTemplate extends PromptTemplate {
|
|
603
|
-
compiledTemplate: Template;
|
|
604
|
-
static isTemplate(templateOpt: PromptTemplateOptions | string): boolean;
|
|
605
|
-
getVariables(template?: Template): string[];
|
|
606
|
-
_initialize(options?: PromptTemplateOptions): void;
|
|
607
|
-
_format(data: Record<string, any>): string;
|
|
608
|
-
}
|
|
609
|
-
declare function createHfValueFunc(fn: Function): (_data: any) => Function;
|
|
610
|
-
|
|
611
|
-
/**
|
|
612
|
-
* Type that represents a node in a parsed format string. It can be either
|
|
613
|
-
* a literal text or a variable name.
|
|
614
|
-
*/
|
|
615
|
-
type FStringPromptTemplateNode = {
|
|
616
|
-
type: "literal";
|
|
617
|
-
text: string;
|
|
618
|
-
} | {
|
|
619
|
-
type: "variable";
|
|
620
|
-
name: string;
|
|
621
|
-
};
|
|
622
|
-
/**
|
|
623
|
-
* Type that represents a function that takes a template string and
|
|
624
|
-
* returns an array of `ParsedFStringNode`.
|
|
625
|
-
*
|
|
626
|
-
* extract from langchain.js/langchain-core/src/prompts/template.ts
|
|
627
|
-
*/
|
|
628
|
-
declare function parseFString(template: string): FStringPromptTemplateNode[];
|
|
629
|
-
/**
|
|
630
|
-
* Type that represents a function that takes a template string and a set
|
|
631
|
-
* of input values, and returns a string where all variables in the
|
|
632
|
-
* template have been replaced with their corresponding values.
|
|
633
|
-
*/
|
|
634
|
-
declare function interpolateFString(nodes: FStringPromptTemplateNode[], values: Record<string, any>): string;
|
|
635
|
-
|
|
636
|
-
declare class FStringPromptTemplate extends PromptTemplate {
|
|
637
|
-
compiledTemplate: FStringPromptTemplateNode[];
|
|
638
|
-
static isTemplate(templateOpt: PromptTemplateOptions | string): boolean;
|
|
639
|
-
getVariables(template?: FStringPromptTemplateNode[]): string[];
|
|
640
|
-
_initialize(options?: PromptTemplateOptions): void;
|
|
641
|
-
_format(data: Record<string, any>): string;
|
|
642
|
-
}
|
|
643
|
-
|
|
644
|
-
declare class GolangPromptTemplate extends PromptTemplate {
|
|
645
|
-
static isTemplate(templateOpt: PromptTemplateOptions | string): boolean | undefined;
|
|
646
|
-
getVariables(template: string): string[];
|
|
647
|
-
_initialize(options?: PromptTemplateOptions): void;
|
|
648
|
-
_format(data: Record<string, any>): string;
|
|
649
|
-
}
|
|
650
|
-
|
|
651
|
-
declare class EnvPromptTemplate extends PromptTemplate {
|
|
652
|
-
static isTemplate(templateOpt: PromptTemplateOptions | string): boolean;
|
|
653
|
-
getVariables(template?: string): string[];
|
|
654
|
-
_initialize(options?: PromptTemplateOptions): void;
|
|
655
|
-
_format(data: Record<string, any>): string;
|
|
656
|
-
}
|
|
657
|
-
|
|
658
220
|
declare function sortedValues<T>(values: Record<string, T>): T[];
|
|
659
|
-
interface FewShotPromptTemplateOptions<T = any> extends
|
|
221
|
+
interface FewShotPromptTemplateOptions<T = any> extends StringTemplateOptions {
|
|
660
222
|
/**
|
|
661
223
|
* The few shot examples to use in the prompt.
|
|
662
224
|
*/
|
|
@@ -664,7 +226,7 @@ interface FewShotPromptTemplateOptions<T = any> extends PromptTemplateOptions {
|
|
|
664
226
|
/**
|
|
665
227
|
* An {@link PromptTemplate} used to format a single example.
|
|
666
228
|
*/
|
|
667
|
-
examplePrompt:
|
|
229
|
+
examplePrompt: StringTemplate | StringTemplateOptions;
|
|
668
230
|
/**
|
|
669
231
|
* String separator used to join the prefix, the examples, and suffix.
|
|
670
232
|
*/
|
|
@@ -680,9 +242,9 @@ interface FewShotPromptTemplateOptions<T = any> extends PromptTemplateOptions {
|
|
|
680
242
|
*/
|
|
681
243
|
suffix?: string;
|
|
682
244
|
}
|
|
683
|
-
declare class FewShotPromptTemplate<T = any> extends
|
|
245
|
+
declare class FewShotPromptTemplate<T = any> extends StringTemplate {
|
|
684
246
|
examples: PromptExamples<T>;
|
|
685
|
-
examplePrompt:
|
|
247
|
+
examplePrompt: StringTemplate | undefined;
|
|
686
248
|
suffix: string;
|
|
687
249
|
exampleSeparator: string;
|
|
688
250
|
prefix: string;
|
|
@@ -693,103 +255,6 @@ declare class FewShotPromptTemplate<T = any> extends PromptTemplate {
|
|
|
693
255
|
toJSON(options?: this): FewShotPromptTemplateOptions<T>;
|
|
694
256
|
}
|
|
695
257
|
|
|
696
|
-
/**
|
|
697
|
-
* Parse and interpolate template
|
|
698
|
-
* @param str golang style template
|
|
699
|
-
* @param variables object of variables to insert
|
|
700
|
-
*/
|
|
701
|
-
declare function interpolateGolangTemplate(str: string, variables: Record<string, any>, initVars?: boolean): string;
|
|
702
|
-
|
|
703
|
-
declare function getEnvVairables(value: string): string[];
|
|
704
|
-
declare function interpolateEnv(value: string, processEnv: Record<string, any>, parsed?: Record<string, any>): any;
|
|
705
|
-
/**
|
|
706
|
-
* Expand environment variables in the parsed object
|
|
707
|
-
* @param options.processEnv Specify an object to write your secrets to. Defaults to `process.env` environment variables.
|
|
708
|
-
* @param options.parsed Specify an object to provide the value of environment variables.
|
|
709
|
-
*
|
|
710
|
-
* Follows these rules to handle environment variable expansion:
|
|
711
|
-
*
|
|
712
|
-
* 1. Simple Variable Expansion: If a string contains `$KEY`, it will be replaced by the value of the environment variable named `KEY`.
|
|
713
|
-
* 2. Braced Variable Expansion: When a string contains `${KEY}`, it also looks up the environment variable named `KEY`.
|
|
714
|
-
* This syntax is typically used to disambiguate variable names that contain special characters.
|
|
715
|
-
* 3. Escaped Dollar Sign: If you want to include a literal `$` followed by a variable name, you can escape it with a backslash (`\$KEY`).
|
|
716
|
-
* This ensures the `$` character is treated as part of the literal string rather than a variable reference.
|
|
717
|
-
* 4. Default Value: In the case of `${KEY:-default}` or `${KEY-default}`, the engine first tries to expand the KEY environment variable.
|
|
718
|
-
* If there's no such environment variable, it will use default as the fallback value.
|
|
719
|
-
*
|
|
720
|
-
* @example
|
|
721
|
-
* const myEnv = {}
|
|
722
|
-
* const env = {
|
|
723
|
-
* processEnv: myEnv,
|
|
724
|
-
* parsed: {
|
|
725
|
-
* WORD: 'World',
|
|
726
|
-
* HELLO: 'Hello ${WORD}'
|
|
727
|
-
* }
|
|
728
|
-
* }
|
|
729
|
-
* expandEnv.expand(env)
|
|
730
|
-
*
|
|
731
|
-
* console.log(myEnv.HELLO) // Hello World
|
|
732
|
-
* console.log(process.env.HELLO) // undefined
|
|
733
|
-
*/
|
|
734
|
-
declare function expandEnv(options: DotenvExpandOptions): DotenvExpandOptions;
|
|
735
|
-
/**
|
|
736
|
-
* Expands environment variables in an object/array or string.
|
|
737
|
-
*
|
|
738
|
-
* This function replaces placeholders like `${VAR}` in strings and recursively
|
|
739
|
-
* processes objects and arrays with environment variable references.
|
|
740
|
-
*
|
|
741
|
-
* @param obj - The object/array or string to be processed. Can be any value, but
|
|
742
|
-
* primarily designed for objects, array and strings.
|
|
743
|
-
* @param options - Configuration options:
|
|
744
|
-
* - processEnv: - An object to source environment variables from, defaults to `process.env`.
|
|
745
|
-
* - parsed: - Specify an object to provide the value of environment variables.
|
|
746
|
-
* @returns - Returns the expanded object or string.
|
|
747
|
-
*
|
|
748
|
-
* @example
|
|
749
|
-
* const obj = {
|
|
750
|
-
* name: 'MyApp',
|
|
751
|
-
* envVar: '${ENV_VAR_NAME}',
|
|
752
|
-
* config: {
|
|
753
|
-
* url: 'http://${HOST}:${PORT}'
|
|
754
|
-
* },
|
|
755
|
-
* list: ['item1', '${ITEM2}']
|
|
756
|
-
* };
|
|
757
|
-
* // the expandedObj will have the actual values instead of placeholders.
|
|
758
|
-
* const expandedObj = expandObjEnv(obj, { processEnv: myCustomEnv }); // Assuming 'ENV_VAR_NAME' is defined as 'Production' and 'HOST', 'PORT', 'ITEM2' are set,
|
|
759
|
-
*
|
|
760
|
-
*/
|
|
761
|
-
declare function expandObjEnv(obj: any, options?: DotenvExpandOptions, parsedObjs?: WeakSet<any>): any;
|
|
762
|
-
interface DotenvPopulateInput {
|
|
763
|
-
[name: string]: string | undefined;
|
|
764
|
-
}
|
|
765
|
-
interface DotenvParseInput {
|
|
766
|
-
[name: string]: string | undefined;
|
|
767
|
-
}
|
|
768
|
-
interface DotenvParseOutput {
|
|
769
|
-
[name: string]: string | undefined;
|
|
770
|
-
}
|
|
771
|
-
interface DotenvExpandOptions {
|
|
772
|
-
error?: Error;
|
|
773
|
-
/**
|
|
774
|
-
* Default: `process.env`
|
|
775
|
-
*
|
|
776
|
-
* Specify an object to write your secrets to. Defaults to process.env environment variables.
|
|
777
|
-
*
|
|
778
|
-
* example: `const processEnv = {}; require('dotenv').config({ processEnv: processEnv })`
|
|
779
|
-
*/
|
|
780
|
-
processEnv?: DotenvPopulateInput;
|
|
781
|
-
/**
|
|
782
|
-
* Default: `object`
|
|
783
|
-
*
|
|
784
|
-
* Object coming from dotenv's parsed result.
|
|
785
|
-
*/
|
|
786
|
-
parsed?: DotenvParseInput;
|
|
787
|
-
}
|
|
788
|
-
interface DotenvExpandOutput {
|
|
789
|
-
error?: Error;
|
|
790
|
-
parsed?: DotenvParseOutput;
|
|
791
|
-
}
|
|
792
|
-
|
|
793
258
|
interface SplitSentenceOptions {
|
|
794
259
|
best?: boolean;
|
|
795
260
|
completeSentence?: boolean;
|
|
@@ -871,7 +336,39 @@ declare function splitParagraph(value: string, options?: SplitSentenceOptions):
|
|
|
871
336
|
*/
|
|
872
337
|
declare function truncTo(n: number, dec?: number, up?: number): number;
|
|
873
338
|
|
|
874
|
-
|
|
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>;
|
|
875
372
|
|
|
876
373
|
declare const EventName = "event";
|
|
877
374
|
declare const EventBusName = "event-bus";
|
|
@@ -894,6 +391,85 @@ declare function getEventableClass(Backend: any): {
|
|
|
894
391
|
};
|
|
895
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);
|
|
896
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
|
+
|
|
897
473
|
declare function isWebStream(val: any): val is ReadableStream<any> | WritableStream<any>;
|
|
898
474
|
|
|
899
475
|
declare const RStreamErrCode = 600;
|
|
@@ -1044,93 +620,7 @@ interface HashAlgoParams {
|
|
|
1044
620
|
}
|
|
1045
621
|
declare function hashStream(stream: ReadableStream, { hashAlgo, seed, outputType }?: HashAlgoParams): Promise<string | Uint8Array<ArrayBufferLike>>;
|
|
1046
622
|
declare function hash(value: IDataType, { hashAlgo, seed, outputType }?: HashAlgoParams): Promise<string | Uint8Array<ArrayBufferLike>>;
|
|
1047
|
-
|
|
1048
|
-
/**
|
|
1049
|
-
* Regular expression pattern for reserved characters in a filename.
|
|
1050
|
-
* do not use /g global option here: when the regex is executed multiple times, it will always begin where it left off last time.
|
|
1051
|
-
*/
|
|
1052
|
-
declare const FilenameReservedRegex: RegExp;
|
|
1053
|
-
/**
|
|
1054
|
-
* Regular expression pattern for reserved names on Windows systems.
|
|
1055
|
-
*/
|
|
1056
|
-
declare const WindowsReservedNameRegex: RegExp;
|
|
1057
|
-
/**
|
|
1058
|
-
* Returns a new regular expression instance for reserved filename characters with the 'g' flag.
|
|
1059
|
-
* use this to reset the with global option
|
|
1060
|
-
* @returns A compiled regular expression for reserved filename characters.
|
|
1061
|
-
*/
|
|
1062
|
-
declare function filenameReservedRegex(): RegExp;
|
|
1063
|
-
/**
|
|
1064
|
-
* Returns a new regular expression instance for control characters in a filename with the 'g' flag.
|
|
1065
|
-
* @returns A compiled regular expression for control characters in a filename.
|
|
1066
|
-
*/
|
|
1067
|
-
declare function reControlCharsRegex(): RegExp;
|
|
1068
|
-
/**
|
|
1069
|
-
* Validates if a given string is a valid filename.
|
|
1070
|
-
* @param {string} filename - The filename to be validated.
|
|
1071
|
-
* @returns True if the filename is valid, false otherwise.
|
|
1072
|
-
* @throws {TypeError} If the input is not a string.
|
|
1073
|
-
* @example
|
|
1074
|
-
* isValidFilename('myFile.txt'); // Returns true
|
|
1075
|
-
* isValidFilename('my<file.txt'); // Returns false
|
|
1076
|
-
*/
|
|
1077
|
-
declare function isValidFilename(filename: string): boolean | "";
|
|
1078
|
-
/**
|
|
1079
|
-
* Validates whether the given filepath is valid.
|
|
1080
|
-
* @param filepath - The filepath to be checked, represented as a string.
|
|
1081
|
-
* @returns A boolean indicating whether the filepath is valid. Returns true if valid; false otherwise.
|
|
1082
|
-
*/
|
|
1083
|
-
declare function isValidFilepath(filepath: string): boolean;
|
|
1084
|
-
interface SanitizeFilenameOptions {
|
|
1085
|
-
replacement?: string;
|
|
1086
|
-
maxLength?: number;
|
|
1087
|
-
}
|
|
1088
|
-
/**
|
|
1089
|
-
* Sanitizes a given filename by replacing invalid characters with a specified replacement character or a default.
|
|
1090
|
-
* @param filename - The filename to sanitize, represented as a string.
|
|
1091
|
-
* @param options - An optional object containing configuration options:
|
|
1092
|
-
* - `replacement` {string} - The character to replace invalid characters with. Default is '!'. Cannot contain reserved filename characters.
|
|
1093
|
-
* - `maxLength` {number} - The maximum length of the sanitized filename. Default is `MAX_FILENAME_LENGTH`.
|
|
1094
|
-
* @returns The sanitized filename.
|
|
1095
|
-
* @throws {Error} - If the `replacement` contains reserved filename characters or control characters.
|
|
1096
|
-
*/
|
|
1097
|
-
declare function sanitizeFilename(filename: string, options?: SanitizeFilenameOptions): string;
|
|
1098
|
-
/**
|
|
1099
|
-
* Sanitizes each part of a file path and reassembles it, ensuring the path is valid according to provided options.
|
|
1100
|
-
* @param filepath - The file path to sanitize, represented as a string.
|
|
1101
|
-
* @param options - Optional settings for sanitization, extending `SanitizeFilenameOptions`. Allows customization of replacement characters and maximum filename length.
|
|
1102
|
-
* @returns The sanitized file path as a string.
|
|
1103
|
-
*/
|
|
1104
|
-
declare function sanitizeFilepath(filepath: string, options?: SanitizeFilenameOptions): string;
|
|
1105
|
-
/**
|
|
1106
|
-
* Retrieves multi-level file extension
|
|
1107
|
-
* @param filename The file name
|
|
1108
|
-
* @param level The level, default is 1, indicating the number of extension levels to retrieve
|
|
1109
|
-
* @returns Returns a concatenated string of multiple extensions, or an empty string if no extension is found
|
|
1110
|
-
*/
|
|
1111
|
-
declare function getMultiLevelExtname(filename: string, level?: number): string;
|
|
1112
|
-
/**
|
|
1113
|
-
* Calculates the level of an extension name.
|
|
1114
|
-
*
|
|
1115
|
-
* The level represents the number of dots ('.') in the extension name, excluding the first dot which separates
|
|
1116
|
-
* the base filename from the extension. For example, the level of ".txt" is 1, and the level of ".tar.gz" is 2.
|
|
1117
|
-
*
|
|
1118
|
-
* @param extName - The extension name to analyze. It should start with a dot ('.').
|
|
1119
|
-
* @returns The level of the extension name, which is the count of dots minus one.
|
|
1120
|
-
*
|
|
1121
|
-
* @example
|
|
1122
|
-
* ```typescript
|
|
1123
|
-
* // Returns 0
|
|
1124
|
-
* extNameLevel("no-file-ext");
|
|
1125
|
-
*
|
|
1126
|
-
* // Returns 2
|
|
1127
|
-
* extNameLevel(".tar.gz");
|
|
1128
|
-
*
|
|
1129
|
-
* // Returns 1
|
|
1130
|
-
* extNameLevel(".json5");
|
|
1131
|
-
* ```
|
|
1132
|
-
*/
|
|
1133
|
-
declare function extNameLevel(extName: string): number;
|
|
623
|
+
declare function hashObject(value: any, options?: HashAlgoParams): Promise<string | Uint8Array<ArrayBufferLike>>;
|
|
1134
624
|
|
|
1135
625
|
/**
|
|
1136
626
|
* Checks if the provided model name matches the given rule.
|
|
@@ -1235,6 +725,7 @@ declare function decodeCharset(result: Buffer, encoding?: BufferEncoding): strin
|
|
|
1235
725
|
* @param dir - A single directory path or an array of directory paths to start the search from.
|
|
1236
726
|
* @param options.isFileMatched - An optional callback that determines whether a file should be included in the result.
|
|
1237
727
|
* @param options.signal - An optional signal to abort the operation.
|
|
728
|
+
* @param options.resolveSymlinks - Whether to resolve symbolic links to their real paths. Defaults to true.
|
|
1238
729
|
* @returns An array of file paths that match the criteria.
|
|
1239
730
|
*
|
|
1240
731
|
* @example
|
|
@@ -1247,6 +738,7 @@ declare function readFilenamesRecursiveSync(dir: string | string[], options?: {
|
|
|
1247
738
|
isFileMatched?: (filepath: string, file: fs.Dirent | fs.Stats) => boolean;
|
|
1248
739
|
signal?: AbortSignal;
|
|
1249
740
|
level?: number;
|
|
741
|
+
resolveSymlinks?: boolean;
|
|
1250
742
|
}): string[];
|
|
1251
743
|
/**
|
|
1252
744
|
* Resolves the real file path, handling symbolic links.
|
|
@@ -1275,10 +767,6 @@ declare function getFileMetaInfo(filepath: string): Promise<IFileMetaInfo>;
|
|
|
1275
767
|
declare function getHashAlgoBySize(size: number): HashAlgorithm;
|
|
1276
768
|
declare function detectCharset(content: Buffer | string, options?: any): string;
|
|
1277
769
|
|
|
1278
|
-
declare function registerYamlTag(tags: any): void;
|
|
1279
|
-
declare function parseYaml(content: string, options?: ParseOptions & DocumentOptions & SchemaOptions & ToJSOptions): any;
|
|
1280
|
-
declare function stringifyYaml(content: any, options?: DocumentOptions & SchemaOptions & ParseOptions & CreateNodeOptions & ToStringOptions): string;
|
|
1281
|
-
|
|
1282
770
|
interface ConfigFilesFilter {
|
|
1283
771
|
after?: {
|
|
1284
772
|
[filepath: string]: number;
|
|
@@ -1358,8 +846,11 @@ declare function jsonToMarkdownStr(mem: any, options?: {
|
|
|
1358
846
|
visiting?: Set<any>;
|
|
1359
847
|
objectTag?: string;
|
|
1360
848
|
arrayTag?: string;
|
|
849
|
+
parent?: any;
|
|
850
|
+
title?: string | boolean;
|
|
1361
851
|
}): string;
|
|
1362
852
|
|
|
853
|
+
declare function DefaultDateFormat(format?: string): string;
|
|
1363
854
|
declare function toDateTime(date: Date | string | number): Date | undefined;
|
|
1364
855
|
declare function textToDate(date: string, format?: string): Date;
|
|
1365
856
|
declare function dateToText(date: Date, format?: string): string;
|
|
@@ -1627,7 +1118,7 @@ declare function getPackageDir(cwd: string): string;
|
|
|
1627
1118
|
*
|
|
1628
1119
|
* @param parentDir - The directory to check as the potential parent.
|
|
1629
1120
|
* @param childDir - The directory to check as the potential child.
|
|
1630
|
-
* @returns true if `childDir` is a subdirectory of `parentDir
|
|
1121
|
+
* @returns true if `childDir` is a subdirectory of `parentDir` or same folder, otherwise false.
|
|
1631
1122
|
*
|
|
1632
1123
|
* @example
|
|
1633
1124
|
* ```typescript
|
|
@@ -1657,11 +1148,44 @@ declare function hasDirectoryIn(dir: string, dirs?: string[]): boolean | undefin
|
|
|
1657
1148
|
* @returns The updated destination array with newly assigned directories from the source.
|
|
1658
1149
|
*/
|
|
1659
1150
|
declare function assignDirs(dest: string[], src: string[]): string[];
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
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;
|
|
1184
|
+
|
|
1185
|
+
declare function isRegExp(value: any): boolean;
|
|
1186
|
+
|
|
1187
|
+
declare function stripConsoleColor(str: any): any;
|
|
1188
|
+
|
|
1665
1189
|
declare const LLM_TOKENIZER_NAMES: {
|
|
1666
1190
|
'deepseek-ai/DeepSeek-V2-Lite-Chat': string;
|
|
1667
1191
|
'Qwen/Qwen2.5-0.5B': string;
|
|
@@ -1746,6 +1270,175 @@ declare function truncateToTokenLimit(content: string, options?: ITruncateToToke
|
|
|
1746
1270
|
declare function truncateToTokenLimitEx(sentences: string[], options?: ITruncateToTokenLimitOptions): Promise<string[]>;
|
|
1747
1271
|
declare function truncateByToken(content: string, options?: ITruncateToTokenLimitOptions): Promise<void>;
|
|
1748
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
|
+
|
|
1749
1442
|
/**
|
|
1750
1443
|
Returns a boolean for whether the two given types are equal.
|
|
1751
1444
|
|
|
@@ -1778,6 +1471,377 @@ type IsEqual<A, B> =
|
|
|
1778
1471
|
? true
|
|
1779
1472
|
: false;
|
|
1780
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
|
+
|
|
1781
1845
|
/**
|
|
1782
1846
|
Filter out keys from an object.
|
|
1783
1847
|
|
|
@@ -1818,6 +1882,10 @@ type ExceptOptions = {
|
|
|
1818
1882
|
requireExactProps?: boolean;
|
|
1819
1883
|
};
|
|
1820
1884
|
|
|
1885
|
+
type DefaultExceptOptions = {
|
|
1886
|
+
requireExactProps: false;
|
|
1887
|
+
};
|
|
1888
|
+
|
|
1821
1889
|
/**
|
|
1822
1890
|
Create a type from an object type without certain keys.
|
|
1823
1891
|
|
|
@@ -1847,11 +1915,34 @@ type FooWithoutB = Except<Foo, 'b', {requireExactProps: true}>;
|
|
|
1847
1915
|
|
|
1848
1916
|
const fooWithoutB: FooWithoutB = {a: 1, b: '2'};
|
|
1849
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'; }
|
|
1850
1938
|
```
|
|
1851
1939
|
|
|
1852
1940
|
@category Object
|
|
1853
1941
|
*/
|
|
1854
|
-
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>> = {
|
|
1855
1946
|
[KeyType in keyof ObjectType as Filter<KeyType, KeysType>]: ObjectType[KeyType];
|
|
1856
1947
|
} & (Options['requireExactProps'] extends true
|
|
1857
1948
|
? Partial<Record<KeysType, never>>
|
|
@@ -1881,6 +1972,16 @@ const responder: RequireAtLeastOne<Responder, 'text' | 'json'> = {
|
|
|
1881
1972
|
type RequireAtLeastOne<
|
|
1882
1973
|
ObjectType,
|
|
1883
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,
|
|
1884
1985
|
> = {
|
|
1885
1986
|
// For each `Key` in `KeysType` make a mapped type:
|
|
1886
1987
|
[Key in KeysType]-?: Required<Pick<ObjectType, Key>> & // 1. Make `Key`'s type required
|
|
@@ -1950,7 +2051,7 @@ declare function isSameString(str1: string, str2: string): boolean;
|
|
|
1950
2051
|
declare const DEFAULT_CONFIG_NAME = ".ai";
|
|
1951
2052
|
type Config = any;
|
|
1952
2053
|
declare function loadConfigFile(filename: string, searchPaths?: string[]): any;
|
|
1953
|
-
declare function expandConfig(config: any, defaultConfig
|
|
2054
|
+
declare function expandConfig(config: any, defaultConfig?: any): any;
|
|
1954
2055
|
declare function loadConfig(filename: string, config: Config): any;
|
|
1955
2056
|
declare function loadAIConfig(config: Config): any;
|
|
1956
2057
|
declare function getXDGConfigs(config: Config): {
|
|
@@ -1960,6 +2061,8 @@ declare function getXDGConfigs(config: Config): {
|
|
|
1960
2061
|
XDG_BIN_HOME: string;
|
|
1961
2062
|
};
|
|
1962
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;
|
|
1963
2066
|
|
|
1964
2067
|
/**
|
|
1965
2068
|
* @callback BeforeShutdownListener
|
|
@@ -1991,4 +2094,334 @@ declare function shutdown(signalOrEvent?: string | number, exitCode?: number | s
|
|
|
1991
2094
|
declare function beforeShutdown(listener: BeforeShutdownListener): BeforeShutdownListener | undefined;
|
|
1992
2095
|
declare function initShutdown(): void;
|
|
1993
2096
|
|
|
1994
|
-
|
|
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 };
|