@isdk/ai-tool 0.3.0 → 0.5.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/dist/chunk-VIG2GB47.mjs +39 -1
- package/dist/chunk-VJ45JQBR.mjs +7829 -0
- package/dist/funcs.d.mts +3 -2
- package/dist/funcs.d.ts +3 -2
- package/dist/funcs.js +5156 -1
- package/dist/funcs.mjs +29 -1
- package/dist/index-Br-4ZYgE.d.mts +892 -0
- package/dist/index-Br-4ZYgE.d.ts +892 -0
- package/dist/index.d.mts +206 -238
- package/dist/index.d.ts +206 -238
- package/dist/index.js +8132 -1
- package/dist/index.mjs +476 -1
- package/dist/test/util.js +101 -1
- package/dist/test/util.mjs +30 -1
- package/package.json +31 -31
- package/dist/chunk-JHHFTTVE.mjs +0 -1
- package/dist/index-BC3GQn6-.d.mts +0 -488
- package/dist/index-BC3GQn6-.d.ts +0 -488
- package/docs/README.md +0 -250
- package/docs/_media/CONTRIBUTING.md +0 -18
- package/docs/_media/LICENSE-MIT +0 -22
- package/docs/classes/AbortError.md +0 -368
- package/docs/classes/AlreadyExistsError.md +0 -348
- package/docs/classes/BaseError.md +0 -359
- package/docs/classes/CancelableAbility.md +0 -379
- package/docs/classes/ClientTools.md +0 -2691
- package/docs/classes/CommonError.md +0 -377
- package/docs/classes/ConfigFile.md +0 -333
- package/docs/classes/EventClient.md +0 -3119
- package/docs/classes/EventServer.md +0 -3149
- package/docs/classes/EventToolFunc.md +0 -2533
- package/docs/classes/FStringPromptTemplate.md +0 -1150
- package/docs/classes/FewShotPromptTemplate.md +0 -1186
- package/docs/classes/GolangPromptTemplate.md +0 -1150
- package/docs/classes/HFEnvironment.md +0 -186
- package/docs/classes/HFInterpreter.md +0 -75
- package/docs/classes/HFTemplate.md +0 -67
- package/docs/classes/HfPromptTemplate.md +0 -1150
- package/docs/classes/IntSet.md +0 -216
- package/docs/classes/NotFoundError.md +0 -348
- package/docs/classes/NotImplementationError.md +0 -348
- package/docs/classes/PromptExampleSelector.md +0 -195
- package/docs/classes/PromptTemplate.md +0 -1079
- package/docs/classes/ReadableStreamError.md +0 -368
- package/docs/classes/ResClientTools.md +0 -2399
- package/docs/classes/ResServerTools.md +0 -2385
- package/docs/classes/SSEChannel.md +0 -270
- package/docs/classes/Semaphore.md +0 -177
- package/docs/classes/ServerTools.md +0 -2609
- package/docs/classes/TaskAbortController.md +0 -137
- package/docs/classes/ToolFunc.md +0 -2147
- package/docs/classes/YamlTypeBaseObject.md +0 -29
- package/docs/enumerations/AsyncFeatureBits.md +0 -37
- package/docs/enumerations/AsyncFeatures.md +0 -37
- package/docs/enumerations/ErrorCode.md +0 -217
- package/docs/enumerations/HashAlgorithm.md +0 -117
- package/docs/functions/AIArgProcessor.md +0 -27
- package/docs/functions/AIStream.md +0 -50
- package/docs/functions/ChoiceArgProcessor.md +0 -27
- package/docs/functions/RateLimit.md +0 -33
- package/docs/functions/TemplateArgProcessor.md +0 -27
- package/docs/functions/backendEventable.md +0 -23
- package/docs/functions/canonicalize.md +0 -21
- package/docs/functions/completeSentences.md +0 -23
- package/docs/functions/concatText.md +0 -23
- package/docs/functions/countLLMTokens.md +0 -23
- package/docs/functions/countRegexMatches.md +0 -33
- package/docs/functions/createAbilityInjector.md +0 -87
- package/docs/functions/createCallbacksTransformer.md +0 -49
- package/docs/functions/createEmptyReadableStream.md +0 -23
- package/docs/functions/createEndWithRepetitionDetector.md +0 -29
- package/docs/functions/createError.md +0 -35
- package/docs/functions/createEventStreamTransformer.md +0 -33
- package/docs/functions/createHfValueFunc.md +0 -29
- package/docs/functions/createLRUCache.md +0 -23
- package/docs/functions/createYamlObjectTag.md +0 -23
- package/docs/functions/dateToText.md +0 -23
- package/docs/functions/decodeCharset.md +0 -23
- package/docs/functions/detectCharset.md +0 -23
- package/docs/functions/encodeLLMTokens.md +0 -23
- package/docs/functions/expandEnv.md +0 -40
- package/docs/functions/expandObjEnv.md +0 -54
- package/docs/functions/extNameLevel.md +0 -43
- package/docs/functions/fileIsExists.md +0 -34
- package/docs/functions/filenameReservedRegex.md +0 -22
- package/docs/functions/filterValidFnScope.md +0 -21
- package/docs/functions/findIndexNonEmptyFrom.md +0 -23
- package/docs/functions/findPort.md +0 -23
- package/docs/functions/formatISO.md +0 -71
- package/docs/functions/formatTextWithSpace.md +0 -59
- package/docs/functions/getAllEnumKeys.md +0 -31
- package/docs/functions/getConfigFileNames.md +0 -23
- package/docs/functions/getConfigs.md +0 -23
- package/docs/functions/getFileMetaInfo.md +0 -21
- package/docs/functions/getHashAlgoBySize.md +0 -21
- package/docs/functions/getKeysPath.md +0 -38
- package/docs/functions/getLLMTokenizer.md +0 -21
- package/docs/functions/getMultiLevelExtname.md +0 -31
- package/docs/functions/getPackageDir.md +0 -39
- package/docs/functions/getRealFilepath.md +0 -34
- package/docs/functions/getResponseErrorReadableStream.md +0 -21
- package/docs/functions/hasDirectoryIn.md +0 -38
- package/docs/functions/hashFile.md +0 -23
- package/docs/functions/hashStream.md +0 -23
- package/docs/functions/hfParse.md +0 -24
- package/docs/functions/hfTokenize.md +0 -25
- package/docs/functions/interpolateEnv.md +0 -25
- package/docs/functions/interpolateFString.md +0 -27
- package/docs/functions/interpolateGolangTemplate.md +0 -31
- package/docs/functions/isLangUsingSpaces.md +0 -21
- package/docs/functions/isListItemString.md +0 -21
- package/docs/functions/isModelNameMatched.md +0 -45
- package/docs/functions/isPunctuationChar.md +0 -36
- package/docs/functions/isRegExp.md +0 -21
- package/docs/functions/isSectionString.md +0 -23
- package/docs/functions/isSentenceEnding.md +0 -21
- package/docs/functions/isSepLineString.md +0 -21
- package/docs/functions/isSubdirectory.md +0 -39
- package/docs/functions/isTitleString.md +0 -23
- package/docs/functions/isValidFilename.md +0 -38
- package/docs/functions/isValidFilepath.md +0 -27
- package/docs/functions/isWebStream.md +0 -21
- package/docs/functions/jsonFilterToWhere.md +0 -45
- package/docs/functions/jsonToMarkdownStr.md +0 -31
- package/docs/functions/loadFileFromPaths.md +0 -54
- package/docs/functions/loadTextFromPaths.md +0 -29
- package/docs/functions/lrucache.md +0 -29
- package/docs/functions/makeToolFuncCancelable.md +0 -23
- package/docs/functions/matchUrlProtocol.md +0 -48
- package/docs/functions/memoize.md +0 -27
- package/docs/functions/messagesToText.md +0 -21
- package/docs/functions/paramsSizeToScaleStr.md +0 -32
- package/docs/functions/parseCommand.md +0 -33
- package/docs/functions/parseDateFormat.md +0 -360
- package/docs/functions/parseFString.md +0 -26
- package/docs/functions/parseISO.md +0 -72
- package/docs/functions/parseJsJson.md +0 -38
- package/docs/functions/parseJsJsonSimpleSync.md +0 -23
- package/docs/functions/parseObjectArgInfo.md +0 -27
- package/docs/functions/parseObjectArgumentInfos.md +0 -25
- package/docs/functions/parseObjectArguments.md +0 -68
- package/docs/functions/parseObjectArgumentsAsArgInfos.md +0 -42
- package/docs/functions/parseYaml.md +0 -21
- package/docs/functions/quoteStr.md +0 -21
- package/docs/functions/reControlCharsRegex.md +0 -21
- package/docs/functions/readFilenamesRecursiveSync.md +0 -47
- package/docs/functions/readTextFileChunks.md +0 -51
- package/docs/functions/readTextFileChunksEx.md +0 -23
- package/docs/functions/readableFromAsyncIterable.md +0 -28
- package/docs/functions/registerCoreTools.md +0 -17
- package/docs/functions/registerYamlTag.md +0 -21
- package/docs/functions/removeMarkdownBold.md +0 -23
- package/docs/functions/removeMarkdownBoldAndItalic.md +0 -23
- package/docs/functions/removeMarkdownItalic.md +0 -23
- package/docs/functions/replaceWithPlaceholder.md +0 -41
- package/docs/functions/restoreFromPlacehoders.md +0 -45
- package/docs/functions/sanitizeFilename.md +0 -37
- package/docs/functions/sanitizeFilepath.md +0 -31
- package/docs/functions/saveConfigFile.md +0 -25
- package/docs/functions/scaleStrToParamsSize.md +0 -27
- package/docs/functions/simplifyObjectArguments.md +0 -21
- package/docs/functions/sortedValues.md +0 -25
- package/docs/functions/splitChunks.md +0 -23
- package/docs/functions/splitParagraph.md +0 -32
- package/docs/functions/splitSentence.md +0 -37
- package/docs/functions/stringifyYaml.md +0 -21
- package/docs/functions/stripConsoleColor.md +0 -21
- package/docs/functions/textToDate.md +0 -23
- package/docs/functions/throwError.md +0 -37
- package/docs/functions/toDate.md +0 -76
- package/docs/functions/toDateTime.md +0 -21
- package/docs/functions/toRegExp.md +0 -34
- package/docs/functions/trimStartOfStreamHelper.md +0 -41
- package/docs/functions/truncTo.md +0 -47
- package/docs/functions/truncateByToken.md +0 -23
- package/docs/functions/truncateToTokenLimit.md +0 -44
- package/docs/functions/truncateToTokenLimitEx.md +0 -23
- package/docs/functions/uuid.md +0 -23
- package/docs/functions/uuidParse.md +0 -21
- package/docs/functions/uuidStringify.md +0 -23
- package/docs/functions/uuidValidate.md +0 -21
- package/docs/functions/uuidVersion.md +0 -21
- package/docs/functions/uuidv1.md +0 -47
- package/docs/functions/uuidv4.md +0 -47
- package/docs/functions/uuidv5.md +0 -51
- package/docs/functions/wait.md +0 -21
- package/docs/functions/xxhash.md +0 -25
- package/docs/functions/xxhash32.md +0 -23
- package/docs/functions/xxhash64.md +0 -23
- package/docs/functions/xxhashAsStr.md +0 -25
- package/docs/globals.md +0 -285
- package/docs/interfaces/AIChatAssistantMessageParam.md +0 -117
- package/docs/interfaces/AIChatContentPartImage.md +0 -31
- package/docs/interfaces/AIChatContentPartText.md +0 -27
- package/docs/interfaces/AIChatMessageParamBase.md +0 -58
- package/docs/interfaces/AIChatMessageToolCall.md +0 -45
- package/docs/interfaces/AIChatSystemMessageParam.md +0 -87
- package/docs/interfaces/AIChatToolMessageParam.md +0 -97
- package/docs/interfaces/AIChatUserMessageParam.md +0 -127
- package/docs/interfaces/AIChoiceConfig.md +0 -77
- package/docs/interfaces/AIResult.md +0 -73
- package/docs/interfaces/AIStreamParser.md +0 -39
- package/docs/interfaces/AIStreamParserOptions.md +0 -21
- package/docs/interfaces/BaseFunc.md +0 -155
- package/docs/interfaces/BaseFuncItem.md +0 -103
- package/docs/interfaces/CancelableAbilityOptions.md +0 -115
- package/docs/interfaces/ClientFuncItem.md +0 -179
- package/docs/interfaces/DotenvExpandOptions.md +0 -47
- package/docs/interfaces/DotenvExpandOutput.md +0 -27
- package/docs/interfaces/DotenvParseInput.md +0 -11
- package/docs/interfaces/DotenvParseOutput.md +0 -11
- package/docs/interfaces/DotenvPopulateInput.md +0 -11
- package/docs/interfaces/EventClientFuncParams.md +0 -55
- package/docs/interfaces/EventServerFuncParams.md +0 -71
- package/docs/interfaces/FewShotPromptTemplateOptions.md +0 -163
- package/docs/interfaces/FuncItem.md +0 -143
- package/docs/interfaces/FuncParam.md +0 -71
- package/docs/interfaces/FuncParams.md +0 -11
- package/docs/interfaces/Funcs.md +0 -11
- package/docs/interfaces/HashAlgoParams.md +0 -37
- package/docs/interfaces/IFileMetaInfo.md +0 -77
- package/docs/interfaces/IReadTextFileChunksOptions.md +0 -157
- package/docs/interfaces/ITruncateToTokenLimitOptions.md +0 -111
- package/docs/interfaces/JsonFilter.md +0 -11
- package/docs/interfaces/ParseObjectArgumentOptions.md +0 -97
- package/docs/interfaces/PromptExampleSelectorOptions.md +0 -36
- package/docs/interfaces/PromptTemplateOptions.md +0 -75
- package/docs/interfaces/RemoteFuncItem.md +0 -168
- package/docs/interfaces/ReplacePlacehoderOptions.md +0 -47
- package/docs/interfaces/ResClientFuncParams.md +0 -35
- package/docs/interfaces/ResServerFuncParams.md +0 -73
- package/docs/interfaces/SanitizeFilenameOptions.md +0 -27
- package/docs/interfaces/SectionStringOptions.md +0 -27
- package/docs/interfaces/ServerFuncItem.md +0 -189
- package/docs/interfaces/ServerFuncParams.md +0 -37
- package/docs/interfaces/SplitSentenceOptions.md +0 -47
- package/docs/interfaces/StreamCallbacksAndOptions.md +0 -95
- package/docs/interfaces/TaskAbortControllers.md +0 -11
- package/docs/interfaces/TaskPromise.md +0 -138
- package/docs/interfaces/ToolFuncPackage.md +0 -49
- package/docs/type-aliases/AIChatContentPart.md +0 -13
- package/docs/type-aliases/AIChatMessageParam.md +0 -13
- package/docs/type-aliases/AIChatRole.md +0 -13
- package/docs/type-aliases/AIMessageType.md +0 -13
- package/docs/type-aliases/AIModelNameRule.md +0 -13
- package/docs/type-aliases/AIModelNameRuleFn.md +0 -21
- package/docs/type-aliases/AIModelNameRules.md +0 -13
- package/docs/type-aliases/AITextGenerationFinishReason.md +0 -13
- package/docs/type-aliases/ActionName.md +0 -13
- package/docs/type-aliases/AsyncTaskId.md +0 -13
- package/docs/type-aliases/EventErrorListenerFn.md +0 -27
- package/docs/type-aliases/EventListenerFn.md +0 -25
- package/docs/type-aliases/FStringPromptTemplateNode.md +0 -16
- package/docs/type-aliases/FuncParamType.md +0 -13
- package/docs/type-aliases/PromptExamples.md +0 -17
- package/docs/type-aliases/PromptTemplateType.md +0 -13
- package/docs/type-aliases/PromptType.md +0 -13
- package/docs/type-aliases/TFunc.md +0 -23
- package/docs/variables/AIChatRoles.md +0 -13
- package/docs/variables/AIMessageTypes.md +0 -13
- package/docs/variables/AITextGenerationFinishReasons.md +0 -13
- package/docs/variables/AbortErrorCode.md +0 -13
- package/docs/variables/ActionNames.md +0 -13
- package/docs/variables/AlreadyExistsErrorCode.md +0 -13
- package/docs/variables/ClientToolFuncSchema.md +0 -87
- package/docs/variables/DefaultAsyncSemaphoreCapacity.md +0 -13
- package/docs/variables/EventBusName.md +0 -13
- package/docs/variables/EventName.md +0 -13
- package/docs/variables/FilenameReservedRegex.md +0 -16
- package/docs/variables/HFBuiltins.md +0 -92
- package/docs/variables/InternalErrorCode.md +0 -13
- package/docs/variables/LLM_TOKENIZER_NAMES.md +0 -83
- package/docs/variables/LLM_TOKENIZER_NAMES_MAP.md +0 -13
- package/docs/variables/NotFoundErrorCode.md +0 -13
- package/docs/variables/NotImplementedErrorCode.md +0 -13
- package/docs/variables/PASSING_SCORE.md +0 -13
- package/docs/variables/PromptTemplateTypes.md +0 -13
- package/docs/variables/PromptTypes.md +0 -16
- package/docs/variables/RStreamErrCode.md +0 -13
- package/docs/variables/RemoteToolFuncSchema.md +0 -87
- package/docs/variables/ResponseRStreamErrCode.md +0 -13
- package/docs/variables/SSEChannelAlreadyClosedErrCode.md +0 -13
- package/docs/variables/ServerToolFuncSchema.md +0 -87
- package/docs/variables/ToolAsyncCancelableBit.md +0 -13
- package/docs/variables/ToolAsyncMultiTaskBit.md +0 -13
- package/docs/variables/ToolAsyncPriorityBit.md +0 -13
- package/docs/variables/ToolFuncSchema.md +0 -125
- package/docs/variables/WindowsReservedNameRegex.md +0 -15
- package/docs/variables/base32768.md +0 -13
- package/docs/variables/defaultTemplateFormat.md +0 -13
- package/docs/variables/event.md +0 -13
- package/docs/variables/eventClient.md +0 -13
- package/docs/variables/eventServer.md +0 -13
- package/docs/variables/lrucache.md +0 -13
- package/docs/variables/mimeType.md +0 -13
- package/docs/variables/uuidNIL.md +0 -13
package/dist/index.d.mts
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import * as custom_ability from 'custom-ability';
|
|
2
|
-
import { AbilityOptions } from 'custom-ability';
|
|
3
2
|
export { createAbilityInjector } from 'custom-ability';
|
|
4
3
|
export { toRegExp } from 'util-ex';
|
|
5
|
-
import { A as
|
|
6
|
-
export { e as AIModelNameRule, d as AIModelNameRuleFn, c as ActionName, b as ActionNames,
|
|
7
|
-
import {
|
|
4
|
+
import { A as AsyncTaskId, a as AIModelNameRules } from './index-Br-4ZYgE.mjs';
|
|
5
|
+
export { e as AIModelNameRule, d as AIModelNameRuleFn, c as ActionName, b as ActionNames, s as AsyncFeatureBits, t as AsyncFeatures, J as BaseFunc, H as BaseFuncItem, n as BinarySemaphore, i as BinarySemaphoreAcquireOptions, B as BinarySemaphoreOptions, j as BinarySemaphoreReleaseOptions, k as BinarySemaphoreReleaserFunc, x as CancelableAbility, C as CancelableAbilityOptions, O as ClientFuncItem, U as ClientToolFuncSchema, Q as ClientTools, D as DefaultAsyncSemaphoreCapacity, a5 as EventClient, a4 as EventClientFuncParams, a8 as EventServer, a7 as EventServerFuncParams, _ as EventToolFunc, I as FuncItem, z as FuncParam, F as FuncParamType, E as FuncParams, K as Funcs, P as PASSING_SCORE, p as RateLimit, f as RemoteFuncItem, R as RemoteToolFuncSchema, aa as ResClientFuncParams, ab as ResClientTools, ac as ResServerFuncParams, ad as ResServerTools, g as SSEChannel, S as SSEChannelAlreadyClosedErrCode, a0 as SecondaryCache, o as Semaphore, h as SemaphoreIsReadyFuncType, l as SemaphoreOptions, m as SemaphoreTaskItem, W as ServerFuncItem, V as ServerFuncParams, Y as ServerToolFuncSchema, X as ServerTools, G as TFunc, u as TaskAbortController, v as TaskAbortControllers, w as TaskPromise, q as ToolAsyncCancelableBit, T as ToolAsyncMultiTaskBit, r as ToolAsyncPriorityBit, M as ToolFunc, L as ToolFuncPackage, N as ToolFuncSchema, a1 as _lrucache, a2 as createLRUCache, $ as event, a6 as eventClient, a9 as eventServer, a3 as lrucache, y as makeToolFuncCancelable, Z as registerCoreTools } from './index-Br-4ZYgE.mjs';
|
|
6
|
+
import { BaseError } from '@isdk/common-error';
|
|
8
7
|
export { AbortError, AbortErrorCode, AlreadyExistsError, AlreadyExistsErrorCode, BaseError, CommonError, ErrorCode, InternalErrorCode, NotFoundError, NotFoundErrorCode, NotImplementationError, NotImplementedErrorCode, createError, throwError } from '@isdk/common-error';
|
|
9
8
|
import { BaseFactory } from 'custom-factory';
|
|
10
|
-
import { Event } from 'events-ex';
|
|
9
|
+
import { Event, EventEmitter } from 'events-ex';
|
|
10
|
+
export { EventEmitter, states as EventStates, eventable, wrapEventEmitter } from 'events-ex';
|
|
11
11
|
import * as _base32768 from 'base32768';
|
|
12
|
+
import { IDataType } from 'hash-wasm';
|
|
12
13
|
import * as fs from 'fs';
|
|
14
|
+
import { ParseOptions, DocumentOptions, SchemaOptions, ToJSOptions, CreateNodeOptions, ToStringOptions } from 'yaml';
|
|
13
15
|
import _memoize, { Options } from 'memoizee';
|
|
14
16
|
export { f as findPort } from './find-port-qS1CZ9c-.mjs';
|
|
15
17
|
import { PreTrainedTokenizer } from '@xenova/transformers';
|
|
@@ -18,225 +20,10 @@ export { canonicalize } from 'json-canonicalize';
|
|
|
18
20
|
export { mimeType } from 'mime-type/with-db';
|
|
19
21
|
export { Config as ConfigFile } from 'load-config-file';
|
|
20
22
|
export { formatISO, parse as parseDateFormat, parseISO, toDate } from 'date-fns';
|
|
23
|
+
export { LRUCache } from 'secondary-cache';
|
|
21
24
|
import 'property-manager';
|
|
22
|
-
import 'secondary-cache';
|
|
23
25
|
import 'http';
|
|
24
26
|
|
|
25
|
-
declare const DefaultAsyncSemaphoreCapacity = 32;
|
|
26
|
-
declare class Deque {
|
|
27
|
-
private _capacity;
|
|
28
|
-
private _length;
|
|
29
|
-
private _front;
|
|
30
|
-
private arr;
|
|
31
|
-
constructor(capacity: number);
|
|
32
|
-
push(item: any): number;
|
|
33
|
-
pop(): any;
|
|
34
|
-
shift(): any;
|
|
35
|
-
get length(): number;
|
|
36
|
-
private checkCapacity;
|
|
37
|
-
private resizeTo;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* A Semaphore implementation for managing concurrency in asynchronous operations.
|
|
41
|
-
* Semaphores allow a fixed number of resources to be accessed concurrently.
|
|
42
|
-
*
|
|
43
|
-
* Example usage:
|
|
44
|
-
*
|
|
45
|
-
* ```typescript
|
|
46
|
-
* const semaphore = new Semaphore(5); // Allows 5 concurrent operations.
|
|
47
|
-
*
|
|
48
|
-
* const semaphore = new Semaphore(
|
|
49
|
-
* 4, // Allow 4 concurrent async calls
|
|
50
|
-
* {
|
|
51
|
-
* capacity: 100 // Prealloc space for 100 tokens
|
|
52
|
-
* }
|
|
53
|
-
* );
|
|
54
|
-
*
|
|
55
|
-
* async function fetchData(x) {
|
|
56
|
-
* await semaphore.acquire()
|
|
57
|
-
* try {
|
|
58
|
-
* console.log(semaphore.pendingCount() + ' calls to fetch are waiting')
|
|
59
|
-
* // ... do some async stuff with x
|
|
60
|
-
* } finally {
|
|
61
|
-
* semaphore.release();
|
|
62
|
-
* }
|
|
63
|
-
* }
|
|
64
|
-
*
|
|
65
|
-
* const data = await Promise.all(array.map(fetchData));
|
|
66
|
-
* ```
|
|
67
|
-
*/
|
|
68
|
-
declare class Semaphore {
|
|
69
|
-
readonly maxConcurrency: number;
|
|
70
|
-
readonly waiting: Deque;
|
|
71
|
-
private free;
|
|
72
|
-
private releaseEmitter;
|
|
73
|
-
private useDefaultTokens;
|
|
74
|
-
private pauseFn?;
|
|
75
|
-
private resumeFn?;
|
|
76
|
-
private paused;
|
|
77
|
-
/**
|
|
78
|
-
* Creates a semaphore object. The first argument is the maximum concurrently number and the second argument is optional.
|
|
79
|
-
*
|
|
80
|
-
* @param maxConcurrency The maximum number of callers allowed to acquire the semaphore concurrently.
|
|
81
|
-
* @param options.initFn Function that is used to initialize the tokens used to manage the semaphore. The default is () => '1'.
|
|
82
|
-
* @param options.pauseFn An optional fuction that is called to opportunistically request pausing the the incoming stream of data,
|
|
83
|
-
* instead of piling up waiting promises and possibly running out of memory. See examples/pausing.js.
|
|
84
|
-
* @param options.resumeFn An optional function that is called when there is room again to accept new waiters on the semaphore.
|
|
85
|
-
* This function must be declared if a pauseFn is declared.
|
|
86
|
-
* @param options.capacity Sets the size of the preallocated waiting list inside the semaphore.
|
|
87
|
-
* This is typically used by high performance where the developer can make a rough estimate of the number of concurrent users of a semaphore.
|
|
88
|
-
*
|
|
89
|
-
* ```ts
|
|
90
|
-
* const readline = require('readline');
|
|
91
|
-
*
|
|
92
|
-
* const rl = readline.createInterface({
|
|
93
|
-
* input: process.stdin,
|
|
94
|
-
* output: process.stdout,
|
|
95
|
-
* terminal: false
|
|
96
|
-
* });
|
|
97
|
-
*
|
|
98
|
-
* function pause() {
|
|
99
|
-
* console.log('Pausing the stream');
|
|
100
|
-
* rl.pause();
|
|
101
|
-
* }
|
|
102
|
-
*
|
|
103
|
-
* function resume() {
|
|
104
|
-
* console.log('Resuming the stream');
|
|
105
|
-
* rl.resume();
|
|
106
|
-
* }
|
|
107
|
-
*
|
|
108
|
-
* const s = new Semaphore(5, { pauseFn: pause, resumeFn: resume });
|
|
109
|
-
*
|
|
110
|
-
* async function parse(line) {
|
|
111
|
-
* await s.acquire();
|
|
112
|
-
*
|
|
113
|
-
* console.log(line);
|
|
114
|
-
*
|
|
115
|
-
* s.release();
|
|
116
|
-
* }
|
|
117
|
-
*
|
|
118
|
-
* rl.on('line', line => {
|
|
119
|
-
* parse(line).catch(console.error);
|
|
120
|
-
* });
|
|
121
|
-
* ```
|
|
122
|
-
*
|
|
123
|
-
*/
|
|
124
|
-
constructor(maxConcurrency: number, { initFn, pauseFn, resumeFn, capacity, }?: {
|
|
125
|
-
initFn?: () => any;
|
|
126
|
-
pauseFn?: () => void;
|
|
127
|
-
resumeFn?: () => void;
|
|
128
|
-
capacity?: number;
|
|
129
|
-
});
|
|
130
|
-
/**
|
|
131
|
-
* Attempt to acquire a token from the semaphore, if one is available immediately. Otherwise, return undefined.
|
|
132
|
-
*/
|
|
133
|
-
tryAcquire(): any | undefined;
|
|
134
|
-
/**
|
|
135
|
-
* Acquire a token from the semaphore, thus decrement the number of available execution slots. If initFn is not used then the return value of the function can be discarded.
|
|
136
|
-
*/
|
|
137
|
-
acquire(signal?: AbortSignal): Promise<any>;
|
|
138
|
-
/**
|
|
139
|
-
* Release the semaphore, thus increment the number of free execution slots. If initFn is used then the token returned by acquire() should be given as an argument when calling this function.
|
|
140
|
-
*/
|
|
141
|
-
release(token?: any): void;
|
|
142
|
-
/**
|
|
143
|
-
* Drains the semaphore and returns all the initialized tokens in an array. Draining is an ideal way to ensure there are no pending async tasks, for example before a process will terminate.
|
|
144
|
-
*/
|
|
145
|
-
drain(): Promise<any[]>;
|
|
146
|
-
/**
|
|
147
|
-
* Returns the number of callers waiting on the semaphore, i.e. the number of pending promises.
|
|
148
|
-
*
|
|
149
|
-
* @returns The number of waiters in the waiting list.
|
|
150
|
-
*/
|
|
151
|
-
pendingCount(): number;
|
|
152
|
-
}
|
|
153
|
-
/**
|
|
154
|
-
* Creates a rate limiter function that blocks with a promise whenever the rate limit is hit and resolves the promise once the call rate is within the limit set by rps. The second argument is optional.
|
|
155
|
-
*
|
|
156
|
-
* @param rps
|
|
157
|
-
* @param options.timeUnit The `timeUnit` is an optional argument setting the width of the rate limiting window in milliseconds.
|
|
158
|
-
* The default `timeUnit` is 1000 ms, therefore making the rps argument act as requests per second limit.
|
|
159
|
-
* @param options.uniformDistribution The `uniformDistribution` argument enforces a discrete uniform distribution over time,
|
|
160
|
-
* instead of the default that allows hitting the function rps time and then pausing for timeWindow milliseconds. Setting
|
|
161
|
-
* the `uniformDistribution` option is mainly useful in a situation where the flow of rate limit function calls is continuous
|
|
162
|
-
* and and occuring faster than timeUnit (e.g. reading a file) and not enabling it would cause the maximum number of calls to
|
|
163
|
-
* resolve immediately (thus exhaust the limit immediately) and therefore the next bunch calls would need to wait for timeWindow
|
|
164
|
-
* milliseconds. However if the flow is sparse then this option may make the code run slower with no advantages.
|
|
165
|
-
*
|
|
166
|
-
* Examples:
|
|
167
|
-
*
|
|
168
|
-
* ```ts
|
|
169
|
-
* async function f() {
|
|
170
|
-
* const lim = RateLimit(5); // rps
|
|
171
|
-
*
|
|
172
|
-
* for (let i = 0; i < n; i++) {
|
|
173
|
-
* await lim();
|
|
174
|
-
* // ... do something async
|
|
175
|
-
* }
|
|
176
|
-
* }
|
|
177
|
-
* ```
|
|
178
|
-
*
|
|
179
|
-
*
|
|
180
|
-
*/
|
|
181
|
-
declare function RateLimit(rps: number, { timeUnit, uniformDistribution, }?: {
|
|
182
|
-
timeUnit?: number;
|
|
183
|
-
uniformDistribution?: boolean;
|
|
184
|
-
}): () => Promise<void>;
|
|
185
|
-
|
|
186
|
-
type AsyncTaskId = string | number;
|
|
187
|
-
interface CancelableAbilityOptions extends AbilityOptions {
|
|
188
|
-
asyncFeatures?: AsyncFeatures;
|
|
189
|
-
maxTaskConcurrency?: number;
|
|
190
|
-
}
|
|
191
|
-
declare class TaskAbortController extends AbortController {
|
|
192
|
-
id?: AsyncTaskId;
|
|
193
|
-
timeoutId?: any;
|
|
194
|
-
streamController?: ReadableStreamDefaultController;
|
|
195
|
-
parent: CancelableAbility;
|
|
196
|
-
constructor(parent: CancelableAbility);
|
|
197
|
-
abort(reason?: string | Error | CommonError, data?: any): void;
|
|
198
|
-
throwRejected(alreadyRejected?: boolean): true | undefined;
|
|
199
|
-
}
|
|
200
|
-
interface TaskAbortControllers {
|
|
201
|
-
[k: AsyncTaskId]: TaskAbortController | undefined;
|
|
202
|
-
}
|
|
203
|
-
interface TaskPromise<T = any> extends Promise<T> {
|
|
204
|
-
task?: TaskAbortController;
|
|
205
|
-
}
|
|
206
|
-
declare interface CancelableAbility {
|
|
207
|
-
_asyncFeatures?: number;
|
|
208
|
-
_maxTaskConcurrency: number | undefined;
|
|
209
|
-
[name: string]: any;
|
|
210
|
-
}
|
|
211
|
-
declare class CancelableAbility {
|
|
212
|
-
generateAsyncTaskId: (taskId?: AsyncTaskId, aborters?: TaskAbortControllers) => AsyncTaskId;
|
|
213
|
-
cleanMultiTaskAborter: (id: AsyncTaskId, aborters: TaskAbortControllers) => void;
|
|
214
|
-
__task_aborter: TaskAbortController | TaskAbortControllers | undefined;
|
|
215
|
-
__task_semaphore: Semaphore | undefined;
|
|
216
|
-
get maxTaskConcurrency(): number | undefined;
|
|
217
|
-
get semaphore(): Semaphore | undefined;
|
|
218
|
-
isAborted(taskId?: AsyncTaskId): boolean;
|
|
219
|
-
getRunningTask(taskId?: AsyncTaskId): TaskAbortController | undefined;
|
|
220
|
-
getRunningTaskCount(): number;
|
|
221
|
-
_generateAsyncTaskId(taskId?: AsyncTaskId, aborters?: TaskAbortControllers): AsyncTaskId;
|
|
222
|
-
$generateAsyncTaskId(taskId?: AsyncTaskId, aborters?: TaskAbortControllers): AsyncTaskId | undefined;
|
|
223
|
-
createAborter(params?: any, taskId?: AsyncTaskId, raiseError?: boolean): TaskAbortController;
|
|
224
|
-
$cleanMultiTaskAborter(id: AsyncTaskId, aborters: TaskAbortControllers): void;
|
|
225
|
-
cleanTaskAborter(aborter: TaskAbortController): void;
|
|
226
|
-
_cleanMultiTaskAborter(id: AsyncTaskId, aborters: TaskAbortControllers): void;
|
|
227
|
-
createTaskPromise<Output = any>(runTask: (params: Record<string, any>, aborter: TaskAbortController) => Promise<Output>, params: Record<string, any>, options?: {
|
|
228
|
-
taskId?: AsyncTaskId;
|
|
229
|
-
raiseError?: boolean;
|
|
230
|
-
}): TaskPromise<Output>;
|
|
231
|
-
runAsyncCancelableTask<Output = any>(params: Record<string, any> | undefined, runTask: (params: Record<string, any>, aborter: TaskAbortController) => Promise<Output>, options?: {
|
|
232
|
-
taskId?: AsyncTaskId;
|
|
233
|
-
raiseError?: boolean;
|
|
234
|
-
}): TaskPromise<Output>;
|
|
235
|
-
abort(reason?: string, data?: any): void;
|
|
236
|
-
}
|
|
237
|
-
type ToolFuncCancelableFn = (Tool: typeof ToolFunc, options?: CancelableAbilityOptions) => typeof ToolFunc;
|
|
238
|
-
declare const makeToolFuncCancelable: ToolFuncCancelableFn;
|
|
239
|
-
|
|
240
27
|
declare const AITextGenerationFinishReasons: readonly ["stop", "length", "content_filter", "tool_calls", "function_call", "abort", "error", "other", null];
|
|
241
28
|
type AITextGenerationFinishReason = typeof AITextGenerationFinishReasons[number];
|
|
242
29
|
interface AIResult<TValue = any, TOptions = any> {
|
|
@@ -260,12 +47,14 @@ declare const AIMessageTypes: readonly ["human", "ai", "generic", "system", "too
|
|
|
260
47
|
type AIMessageType = typeof AIMessageTypes[number];
|
|
261
48
|
declare const AIChatRoles: readonly ["user", "assistant", "system", "tool", "tool_calls"];
|
|
262
49
|
type AIChatRole = (typeof AIChatRoles[number]) & string;
|
|
263
|
-
type AIChatMessageParam = AIChatSystemMessageParam | AIChatUserMessageParam | AIChatAssistantMessageParam | AIChatToolMessageParam;
|
|
50
|
+
type AIChatMessageParam = AIChatMessageParamBase | AIChatSystemMessageParam | AIChatUserMessageParam | AIChatAssistantMessageParam | AIChatToolMessageParam;
|
|
264
51
|
interface AIChatMessageParamBase {
|
|
265
52
|
role: string;
|
|
266
53
|
toRole?: string | string[] | Record<string, Partial<AIChatMessageParam>>;
|
|
267
54
|
replies?: Record<string, Partial<AIChatMessageParam>>;
|
|
268
55
|
private?: boolean;
|
|
56
|
+
tools?: Record<string, string>;
|
|
57
|
+
thinking?: string;
|
|
269
58
|
[name: string]: any;
|
|
270
59
|
}
|
|
271
60
|
interface AIChatSystemMessageParam extends AIChatMessageParamBase {
|
|
@@ -315,6 +104,32 @@ interface AIChatToolMessageParam extends AIChatMessageParamBase {
|
|
|
315
104
|
tool_call_id: string;
|
|
316
105
|
templateFormat?: string;
|
|
317
106
|
}
|
|
107
|
+
interface AIChatToolParam {
|
|
108
|
+
type: string;
|
|
109
|
+
[key: string]: any;
|
|
110
|
+
}
|
|
111
|
+
interface AIChatToolFuncParam extends AIChatToolParam {
|
|
112
|
+
type: 'function';
|
|
113
|
+
function: AIChatToolFunc;
|
|
114
|
+
}
|
|
115
|
+
interface AIChatToolFunc {
|
|
116
|
+
name: string;
|
|
117
|
+
description?: string;
|
|
118
|
+
parameters?: any;
|
|
119
|
+
strict?: boolean;
|
|
120
|
+
}
|
|
121
|
+
type AIChatToolChoiceParam = 'auto' | 'none' | 'required' | AIChatToolChoiceObject;
|
|
122
|
+
interface AIChatToolChoiceObject {
|
|
123
|
+
type: string;
|
|
124
|
+
[key: string]: any;
|
|
125
|
+
}
|
|
126
|
+
interface AIChatToolChoiceFuncObject extends AIChatToolChoiceObject {
|
|
127
|
+
type: 'function';
|
|
128
|
+
function: AIChatToolTypeObject;
|
|
129
|
+
}
|
|
130
|
+
interface AIChatToolTypeObject {
|
|
131
|
+
name: string;
|
|
132
|
+
}
|
|
318
133
|
declare function messagesToText(messages: AIChatMessageParamBase[]): string;
|
|
319
134
|
|
|
320
135
|
/**
|
|
@@ -461,6 +276,7 @@ declare const TOKEN_TYPES: Readonly<{
|
|
|
461
276
|
Text: "Text";
|
|
462
277
|
NumericLiteral: "NumericLiteral";
|
|
463
278
|
BooleanLiteral: "BooleanLiteral";
|
|
279
|
+
NullLiteral: "NullLiteral";
|
|
464
280
|
StringLiteral: "StringLiteral";
|
|
465
281
|
Identifier: "Identifier";
|
|
466
282
|
Equals: "Equals";
|
|
@@ -746,10 +562,12 @@ declare function tojson(value: any, indent?: number | {
|
|
|
746
562
|
indent?: number;
|
|
747
563
|
depth?: number;
|
|
748
564
|
}, depth?: number): string;
|
|
565
|
+
declare function join(value: any, separator?: string): any;
|
|
749
566
|
declare const builtins: {
|
|
750
567
|
randomInt: typeof randomInt;
|
|
751
568
|
select: typeof select;
|
|
752
569
|
tojson: typeof tojson;
|
|
570
|
+
join: typeof join;
|
|
753
571
|
};
|
|
754
572
|
|
|
755
573
|
/**
|
|
@@ -778,7 +596,7 @@ declare class Template {
|
|
|
778
596
|
* @param {string} template The template string
|
|
779
597
|
*/
|
|
780
598
|
constructor(template: string, options?: PreprocessOptions);
|
|
781
|
-
render(items
|
|
599
|
+
render(items?: Record<string, unknown>): string;
|
|
782
600
|
}
|
|
783
601
|
|
|
784
602
|
declare class HfPromptTemplate extends PromptTemplate {
|
|
@@ -830,6 +648,13 @@ declare class GolangPromptTemplate extends PromptTemplate {
|
|
|
830
648
|
_format(data: Record<string, any>): string;
|
|
831
649
|
}
|
|
832
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
|
+
|
|
833
658
|
declare function sortedValues<T>(values: Record<string, T>): T[];
|
|
834
659
|
interface FewShotPromptTemplateOptions<T = any> extends PromptTemplateOptions {
|
|
835
660
|
/**
|
|
@@ -875,7 +700,8 @@ declare class FewShotPromptTemplate<T = any> extends PromptTemplate {
|
|
|
875
700
|
*/
|
|
876
701
|
declare function interpolateGolangTemplate(str: string, variables: Record<string, any>, initVars?: boolean): string;
|
|
877
702
|
|
|
878
|
-
declare function
|
|
703
|
+
declare function getEnvVairables(value: string): string[];
|
|
704
|
+
declare function interpolateEnv(value: string, processEnv: Record<string, any>, parsed?: Record<string, any>): any;
|
|
879
705
|
/**
|
|
880
706
|
* Expand environment variables in the parsed object
|
|
881
707
|
* @param options.processEnv Specify an object to write your secrets to. Defaults to `process.env` environment variables.
|
|
@@ -1051,7 +877,22 @@ declare const EventName = "event";
|
|
|
1051
877
|
declare const EventBusName = "event-bus";
|
|
1052
878
|
type EventListenerFn = (this: Event, name: string, ...args: any) => any;
|
|
1053
879
|
type EventErrorListenerFn = (this: Event, err: Error, name: string, ...args: any) => any;
|
|
1054
|
-
declare
|
|
880
|
+
declare function getEventableClass(Backend: any): {
|
|
881
|
+
new (): {
|
|
882
|
+
name: string;
|
|
883
|
+
_events: any;
|
|
884
|
+
readonly emitter: any;
|
|
885
|
+
on(eventName: string, listener: EventListenerFn): EventEmitter | void;
|
|
886
|
+
once(eventName: string, listener: EventListenerFn): EventEmitter | void;
|
|
887
|
+
off(type: string, listener: EventListenerFn): EventEmitter;
|
|
888
|
+
emit(eventName: string, ...args: any[]): any;
|
|
889
|
+
emitError(err: any, ...args: any[]): any;
|
|
890
|
+
emitAsync(eventName: string, ...args: any[]): Promise<any>;
|
|
891
|
+
};
|
|
892
|
+
_emitter: any;
|
|
893
|
+
readonly emitter: any;
|
|
894
|
+
};
|
|
895
|
+
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);
|
|
1055
896
|
|
|
1056
897
|
declare function isWebStream(val: any): val is ReadableStream<any> | WritableStream<any>;
|
|
1057
898
|
|
|
@@ -1174,10 +1015,6 @@ declare function createCallbacksTransformer<I = any, O = any>(cb: StreamCallback
|
|
|
1174
1015
|
|
|
1175
1016
|
declare function uuid(ver?: 1 | 4 | 5, encode?: boolean): string;
|
|
1176
1017
|
|
|
1177
|
-
declare const base32768: typeof _base32768;
|
|
1178
|
-
|
|
1179
|
-
declare function xxhash32(value: string | object, radix?: number): string;
|
|
1180
|
-
declare function xxhash64(value: string | object, radix?: number): string;
|
|
1181
1018
|
declare enum HashAlgorithm {
|
|
1182
1019
|
md5 = 1,
|
|
1183
1020
|
sha1 = 2,
|
|
@@ -1191,15 +1028,22 @@ declare enum HashAlgorithm {
|
|
|
1191
1028
|
xxhash32 = 112,
|
|
1192
1029
|
xxhash128 = 113
|
|
1193
1030
|
}
|
|
1031
|
+
|
|
1032
|
+
declare function xxhash32(value: string | object, radix?: number): string;
|
|
1033
|
+
declare function xxhash64(value: string | object, radix?: number): string;
|
|
1194
1034
|
type HashValue = string | ArrayBuffer | Buffer;
|
|
1195
1035
|
declare function xxhash(value: HashValue, hashAlgo?: HashAlgorithm, seed?: number): Uint8Array;
|
|
1196
1036
|
declare function xxhashAsStr(value: string | Uint8Array, hashAlgo?: HashAlgorithm, seed?: number): string;
|
|
1037
|
+
|
|
1038
|
+
declare const base32768: typeof _base32768;
|
|
1039
|
+
|
|
1197
1040
|
interface HashAlgoParams {
|
|
1198
1041
|
hashAlgo?: HashAlgorithm;
|
|
1199
1042
|
seed?: number;
|
|
1200
1043
|
outputType?: 'hex' | 'binary' | 'string';
|
|
1201
1044
|
}
|
|
1202
|
-
declare function hashStream(stream: ReadableStream, { hashAlgo, seed, outputType }?: HashAlgoParams): Promise<string | Uint8Array
|
|
1045
|
+
declare function hashStream(stream: ReadableStream, { hashAlgo, seed, outputType }?: HashAlgoParams): Promise<string | Uint8Array<ArrayBufferLike>>;
|
|
1046
|
+
declare function hash(value: IDataType, { hashAlgo, seed, outputType }?: HashAlgoParams): Promise<string | Uint8Array<ArrayBufferLike>>;
|
|
1203
1047
|
|
|
1204
1048
|
/**
|
|
1205
1049
|
* Regular expression pattern for reserved characters in a filename.
|
|
@@ -1377,7 +1221,7 @@ declare function loadFileFromPaths(filename: string, searchPaths?: string[], ext
|
|
|
1377
1221
|
filepath?: string;
|
|
1378
1222
|
exclude?: string[] | string;
|
|
1379
1223
|
signal?: AbortSignal;
|
|
1380
|
-
}): Buffer
|
|
1224
|
+
}): Buffer<ArrayBufferLike>;
|
|
1381
1225
|
declare function loadTextFromPaths(filename: string, searchPaths?: string[], extNames?: string[], options?: {
|
|
1382
1226
|
encoding?: BufferEncoding;
|
|
1383
1227
|
filepath?: string;
|
|
@@ -1417,7 +1261,7 @@ declare function readFilenamesRecursiveSync(dir: string | string[], options?: {
|
|
|
1417
1261
|
* ```
|
|
1418
1262
|
*/
|
|
1419
1263
|
declare function getRealFilepath(filepath: string): string;
|
|
1420
|
-
declare function hashFile(filepath: string, options?: HashAlgoParams): Promise<string | Uint8Array
|
|
1264
|
+
declare function hashFile(filepath: string, options?: HashAlgoParams): Promise<string | Uint8Array<ArrayBufferLike>>;
|
|
1421
1265
|
interface IFileMetaInfo {
|
|
1422
1266
|
name: string;
|
|
1423
1267
|
mtime: Date;
|
|
@@ -1432,8 +1276,8 @@ declare function getHashAlgoBySize(size: number): HashAlgorithm;
|
|
|
1432
1276
|
declare function detectCharset(content: Buffer | string, options?: any): string;
|
|
1433
1277
|
|
|
1434
1278
|
declare function registerYamlTag(tags: any): void;
|
|
1435
|
-
declare function parseYaml(content: string): any;
|
|
1436
|
-
declare function stringifyYaml(content: any): string;
|
|
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;
|
|
1437
1281
|
|
|
1438
1282
|
interface ConfigFilesFilter {
|
|
1439
1283
|
after?: {
|
|
@@ -1560,6 +1404,58 @@ declare class IntSet {
|
|
|
1560
1404
|
toJSON(): number;
|
|
1561
1405
|
}
|
|
1562
1406
|
|
|
1407
|
+
/**
|
|
1408
|
+
* An asynchronous signal gate that blocks operations until a signal is emitted.
|
|
1409
|
+
* This class allows multiple awaiters to wait for a signal and resolves all pending promises with the emitted value.
|
|
1410
|
+
* The gate can be reset to reuse for subsequent signals.
|
|
1411
|
+
*
|
|
1412
|
+
* @example
|
|
1413
|
+
*
|
|
1414
|
+
* ```typescript
|
|
1415
|
+
* // Default type is void, can call signal() without parameters
|
|
1416
|
+
* const gate = new SignalGate();
|
|
1417
|
+
* gate.signal(); // No parameters required
|
|
1418
|
+
*
|
|
1419
|
+
* // Example with explicit type
|
|
1420
|
+
* const valueGate = new SignalGate<number>();
|
|
1421
|
+
* valueGate.signal(42); // Must provide a number value
|
|
1422
|
+
* ```
|
|
1423
|
+
*/
|
|
1424
|
+
declare class SignalGate<T = void> {
|
|
1425
|
+
protected _isSignaled: boolean;
|
|
1426
|
+
protected _signalValue: T | undefined;
|
|
1427
|
+
protected waitQueue: Array<{
|
|
1428
|
+
resolve: (value: T) => void;
|
|
1429
|
+
reject: (error: any) => void;
|
|
1430
|
+
}>;
|
|
1431
|
+
get signaled(): boolean;
|
|
1432
|
+
/**
|
|
1433
|
+
* Emits the signal with an optional value, resolving all pending {@link wait} promises.
|
|
1434
|
+
* Subsequent calls have no effect until {@link reset} is called.
|
|
1435
|
+
*
|
|
1436
|
+
* @param value The value to emit with the signal (only required if T is not void).
|
|
1437
|
+
*/
|
|
1438
|
+
signal(value?: T): void;
|
|
1439
|
+
/**
|
|
1440
|
+
* Resets the gate to its initial state, allowing a new signal to be emitted.
|
|
1441
|
+
*/
|
|
1442
|
+
reset(): void;
|
|
1443
|
+
/**
|
|
1444
|
+
* Aborts all pending waits, rejecting their promises with an error.
|
|
1445
|
+
* This does **not** reset the signal state (the gate remains signaled or unsignaled).
|
|
1446
|
+
*
|
|
1447
|
+
* @param reason The reason for aborting the waits.
|
|
1448
|
+
*/
|
|
1449
|
+
abort(reason?: any): void;
|
|
1450
|
+
/**
|
|
1451
|
+
* Returns a promise that resolves with the emitted signal value.
|
|
1452
|
+
* If called after the signal has been emitted, resolves immediately with the stored value.
|
|
1453
|
+
*
|
|
1454
|
+
* @returns A promise resolving to the signal value (type T).
|
|
1455
|
+
*/
|
|
1456
|
+
wait(): Promise<T>;
|
|
1457
|
+
}
|
|
1458
|
+
|
|
1563
1459
|
/**
|
|
1564
1460
|
* Counts the number of matches for a given regular expression in a specified string.
|
|
1565
1461
|
* This function ensures that the regular expression is used globally by adding the 'g' flag,
|
|
@@ -1592,6 +1488,7 @@ interface ParseObjectArgumentOptions {
|
|
|
1592
1488
|
ignoreIndexNamed?: boolean;
|
|
1593
1489
|
preserveUnresolvedName?: boolean;
|
|
1594
1490
|
skipExpression?: boolean;
|
|
1491
|
+
raiseError?: boolean;
|
|
1595
1492
|
}
|
|
1596
1493
|
/**
|
|
1597
1494
|
* Asynchronously parses a string of object arguments into an actual object.
|
|
@@ -1633,11 +1530,18 @@ interface ParseObjectArgumentOptions {
|
|
|
1633
1530
|
* ```
|
|
1634
1531
|
*/
|
|
1635
1532
|
declare function parseObjectArguments(argsStr: string, scope?: Record<string, any>, options?: ParseObjectArgumentOptions): Promise<any>;
|
|
1533
|
+
declare function ObjectArgsToArgsInfo(args: any): {
|
|
1534
|
+
args: any[];
|
|
1535
|
+
kvArgs?: Record<string, any>;
|
|
1536
|
+
};
|
|
1636
1537
|
declare function simplifyObjectArguments(args: any): any;
|
|
1637
1538
|
declare function parseObjectArgumentInfos(args: ArgInfo[], scope?: Record<string, any>, options?: ParseObjectArgumentOptions): Promise<any>;
|
|
1638
1539
|
declare function ChoiceArgProcessor(argInfo: ArgInfo, _ix: number, scope?: Record<string, any>, options?: ParseObjectArgumentOptions): string | undefined;
|
|
1639
1540
|
declare function TemplateArgProcessor([isNamedArg, arg]: ArgInfo, ix: number, scope?: Record<string, any>, options?: ParseObjectArgumentOptions): Promise<string | undefined>;
|
|
1640
1541
|
declare function AIArgProcessor(argInfo: ArgInfo, ix: number, scope?: Record<string, any>, options?: ParseObjectArgumentOptions): Promise<string | undefined>;
|
|
1542
|
+
declare function isQuoted(s: string): boolean;
|
|
1543
|
+
declare function isStrWrapped(s: string, pairs?: string[]): boolean;
|
|
1544
|
+
declare function ensureQuoted(s: string, quoteChar?: string): string;
|
|
1641
1545
|
declare function quoteStr(str: string): string;
|
|
1642
1546
|
declare function parseObjectArgInfo(argInfo: ArgInfo, ix: number, scope?: Record<string, any>, options?: ParseObjectArgumentOptions): Promise<string>;
|
|
1643
1547
|
/**
|
|
@@ -1659,7 +1563,7 @@ declare function parseObjectArgumentsAsArgInfos(argsStr: string, scope?: Record<
|
|
|
1659
1563
|
declare function parseCommand(commandStr: string, scope?: Record<string, any>, options?: ParseObjectArgumentOptions): Promise<{
|
|
1660
1564
|
command: string;
|
|
1661
1565
|
args?: Record<string, any>;
|
|
1662
|
-
}>;
|
|
1566
|
+
} | undefined>;
|
|
1663
1567
|
interface ReplacePlacehoderOptions {
|
|
1664
1568
|
startChar?: string | string[];
|
|
1665
1569
|
endChar?: string | string[];
|
|
@@ -1745,6 +1649,14 @@ declare function isSubdirectory(parentDir: string, childDir: string): boolean;
|
|
|
1745
1649
|
* hasDirectoryIn('parentdir/subdir', ['parentdir', 'otherdir']); // true
|
|
1746
1650
|
*/
|
|
1747
1651
|
declare function hasDirectoryIn(dir: string, dirs?: string[]): boolean | undefined;
|
|
1652
|
+
/**
|
|
1653
|
+
* Assigns directories from the source array to the destination array if they do not already exist in the destination.
|
|
1654
|
+
*
|
|
1655
|
+
* @param dest - The destination array to which new directories will be added.
|
|
1656
|
+
* @param src - The source array containing directories to be assigned to the destination.
|
|
1657
|
+
* @returns The updated destination array with newly assigned directories from the source.
|
|
1658
|
+
*/
|
|
1659
|
+
declare function assignDirs(dest: string[], src: string[]): string[];
|
|
1748
1660
|
|
|
1749
1661
|
declare function isRegExp(value: any): boolean;
|
|
1750
1662
|
|
|
@@ -1861,8 +1773,8 @@ type Includes<Value extends readonly any[], Item> =
|
|
|
1861
1773
|
@category Utilities
|
|
1862
1774
|
*/
|
|
1863
1775
|
type IsEqual<A, B> =
|
|
1864
|
-
(<G>() => G extends A ? 1 : 2) extends
|
|
1865
|
-
(<G>() => G extends B ? 1 : 2)
|
|
1776
|
+
(<G>() => G extends A & G | G ? 1 : 2) extends
|
|
1777
|
+
(<G>() => G extends B & G | G ? 1 : 2)
|
|
1866
1778
|
? true
|
|
1867
1779
|
: false;
|
|
1868
1780
|
|
|
@@ -2023,4 +1935,60 @@ declare class YamlTypeBaseObject {
|
|
|
2023
1935
|
}
|
|
2024
1936
|
declare function createYamlObjectTag(tag: string, BaseObject: typeof YamlTypeBaseObject): any;
|
|
2025
1937
|
|
|
2026
|
-
|
|
1938
|
+
/**
|
|
1939
|
+
* Compares two strings to check if they are the same.
|
|
1940
|
+
*
|
|
1941
|
+
* This function first checks if the strings have the same length. If they do, it compares the strings character by character.
|
|
1942
|
+
* If the strings are not the same length, it returns false immediately.
|
|
1943
|
+
*
|
|
1944
|
+
* @param str1 - The first string to compare.
|
|
1945
|
+
* @param str2 - The second string to compare.
|
|
1946
|
+
* @returns A boolean indicating whether the two strings are the same.
|
|
1947
|
+
*/
|
|
1948
|
+
declare function isSameString(str1: string, str2: string): boolean;
|
|
1949
|
+
|
|
1950
|
+
declare const DEFAULT_CONFIG_NAME = ".ai";
|
|
1951
|
+
type Config = any;
|
|
1952
|
+
declare function loadConfigFile(filename: string, searchPaths?: string[]): any;
|
|
1953
|
+
declare function expandConfig(config: any, defaultConfig: any): any;
|
|
1954
|
+
declare function loadConfig(filename: string, config: Config): any;
|
|
1955
|
+
declare function loadAIConfig(config: Config): any;
|
|
1956
|
+
declare function getXDGConfigs(config: Config): {
|
|
1957
|
+
XDG_CONFIG_HOME: any;
|
|
1958
|
+
XDG_DATA_HOME: any;
|
|
1959
|
+
XDG_CACHE_HOME: any;
|
|
1960
|
+
XDG_BIN_HOME: string;
|
|
1961
|
+
};
|
|
1962
|
+
declare function expandPath(path: string, config?: any): any;
|
|
1963
|
+
|
|
1964
|
+
/**
|
|
1965
|
+
* @callback BeforeShutdownListener
|
|
1966
|
+
* @param {string} [signalOrEvent] The exit signal or event name received on the process.
|
|
1967
|
+
*/
|
|
1968
|
+
type BeforeShutdownListener = (signalOrEvent: string) => Promise<void> | void;
|
|
1969
|
+
/**
|
|
1970
|
+
* System signals the app will listen to initiate shutdown.
|
|
1971
|
+
* @const {string[]}
|
|
1972
|
+
*
|
|
1973
|
+
* SIGINT, a.k.a Ctrl + C, and SIGTERM by default
|
|
1974
|
+
*/
|
|
1975
|
+
declare const SHUTDOWN_SIGNALS: string[];
|
|
1976
|
+
/**
|
|
1977
|
+
* Main process shutdown handler. Will invoke every previously registered async shutdown listener
|
|
1978
|
+
* in the queue and exit with a code of `0`. Any `Promise` rejections from any listener will
|
|
1979
|
+
* be logged out as a warning, but won't prevent other callbacks from executing.
|
|
1980
|
+
* @param {string} signalOrEvent The exit signal or event name received on the process, defaults to shutdown.
|
|
1981
|
+
* @param {number|string|null} exitCode The optional exit code, defaults to 0.
|
|
1982
|
+
*/
|
|
1983
|
+
declare function shutdown(signalOrEvent?: string | number, exitCode?: number | string | null): Promise<undefined>;
|
|
1984
|
+
/**
|
|
1985
|
+
* Registers a new shutdown listener to be invoked before exiting
|
|
1986
|
+
* the main process. Listener handlers are guaranteed to be called in the order
|
|
1987
|
+
* they were registered.
|
|
1988
|
+
* @param {BeforeShutdownListener} listener The shutdown listener to register.
|
|
1989
|
+
* @returns {BeforeShutdownListener} Echoes back the supplied `listener`.
|
|
1990
|
+
*/
|
|
1991
|
+
declare function beforeShutdown(listener: BeforeShutdownListener): BeforeShutdownListener | undefined;
|
|
1992
|
+
declare function initShutdown(): void;
|
|
1993
|
+
|
|
1994
|
+
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, AsyncTaskId, type BeforeShutdownListener, ChoiceArgProcessor, DEFAULT_CONFIG_NAME, type DotenvExpandOptions, type DotenvExpandOutput, type DotenvParseInput, type DotenvParseOutput, type DotenvPopulateInput, EnvPromptTemplate, EventBusName, type EventErrorListenerFn, type EventListenerFn, EventName, FStringPromptTemplate, type FStringPromptTemplateNode, FewShotPromptTemplate, type FewShotPromptTemplateOptions, FilenameReservedRegex, GolangPromptTemplate, builtins as HFBuiltins, EnvironmentEx as HFEnvironment, Interpreter as HFInterpreter, Template as HFTemplate, type HashAlgoParams, HashAlgorithm, HfPromptTemplate, type IFileMetaInfo, type IReadTextFileChunksOptions, type ITruncateToTokenLimitOptions, IntSet, type JsonFilter, LLM_TOKENIZER_NAMES, LLM_TOKENIZER_NAMES_MAP, ObjectArgsToArgsInfo, type ParseObjectArgumentOptions, PromptExampleSelector, type PromptExampleSelectorOptions, type PromptExamples, PromptTemplate, type PromptTemplateOptions, type PromptTemplateType, PromptTemplateTypes, type PromptType, PromptTypes, RStreamErrCode, ReadableStreamError, type ReplacePlacehoderOptions, ResponseRStreamErrCode, SHUTDOWN_SIGNALS, type SanitizeFilenameOptions, type SectionStringOptions, SignalGate, type SplitSentenceOptions, type StreamCallbacksAndOptions, TemplateArgProcessor, WindowsReservedNameRegex, YamlTypeBaseObject, assignDirs, backendEventable, base32768, beforeShutdown, completeSentences, concatText, countLLMTokens, countRegexMatches, createCallbacksTransformer, createEmptyReadableStream, createEndWithRepetitionDetector, createEventStreamTransformer, createHfValueFunc, createYamlObjectTag, dateToText, decodeCharset, defaultTemplateFormat, detectCharset, encodeLLMTokens, ensureQuoted, expandConfig, expandEnv, expandObjEnv, expandPath, extNameLevel, fileIsExists, filenameReservedRegex, filterValidFnScope, findIndexNonEmptyFrom, formatTextWithSpace, getAllEnumKeys, getConfigFileNames, getConfigs, getEnvVairables, getFileMetaInfo, getHashAlgoBySize, getKeysPath, getLLMTokenizer, getMultiLevelExtname, getPackageDir, getRealFilepath, getResponseErrorReadableStream, getXDGConfigs, hasDirectoryIn, hash, hashFile, hashStream, parse as hfParse, tokenize as hfTokenize, initShutdown, interpolateEnv, interpolateFString, interpolateGolangTemplate, isLangUsingSpaces, isListItemString, isModelNameMatched, isPunctuationChar, isQuoted, isRegExp, isSameString, isSectionString, isSentenceEnding, isSepLineString, isStrWrapped, isSubdirectory, isTitleString, isValidFilename, isValidFilepath, isWebStream, jsonFilterToWhere, jsonToMarkdownStr, loadAIConfig, loadConfig, loadConfigFile, loadFileFromPaths, loadTextFromPaths, matchUrlProtocol, memoize, messagesToText, paramsSizeToScaleStr, parseCommand, parseFString, parseJsJson, parseJsJsonSimpleSync, parseObjectArgInfo, parseObjectArgumentInfos, parseObjectArguments, parseObjectArgumentsAsArgInfos, parseYaml, quoteStr, reControlCharsRegex, readFilenamesRecursiveSync, readTextFileChunks, readTextFileChunksEx, readableFromAsyncIterable, registerYamlTag, removeMarkdownBold, removeMarkdownBoldAndItalic, removeMarkdownItalic, replaceWithPlaceholder, restoreFromPlacehoders, sanitizeFilename, sanitizeFilepath, saveConfigFile, scaleStrToParamsSize, shutdown, simplifyObjectArguments, sortedValues, splitChunks, splitParagraph, splitSentence, stringifyYaml, stripConsoleColor, textToDate, toDateTime, trimStartOfStreamHelper, truncTo, truncateByToken, truncateToTokenLimit, truncateToTokenLimitEx, uuid, wait, xxhash, xxhash32, xxhash64, xxhashAsStr };
|