@isdk/ai-tool 0.4.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 +204 -237
- package/dist/index.d.ts +204 -237
- 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-SIP3XWIH.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 -25
- 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 -107
- 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
|
@@ -0,0 +1,892 @@
|
|
|
1
|
+
import { EventEmitter, Event } from 'events-ex';
|
|
2
|
+
import { AdvancePropertyManager } from 'property-manager';
|
|
3
|
+
import { AbilityOptions } from 'custom-ability';
|
|
4
|
+
import * as _isdk_common_error from '@isdk/common-error';
|
|
5
|
+
import { CommonError } from '@isdk/common-error';
|
|
6
|
+
import { Cache, ICacheOptions } from 'secondary-cache';
|
|
7
|
+
import { IncomingMessage, ServerResponse } from 'http';
|
|
8
|
+
|
|
9
|
+
type FuncParamType = string;
|
|
10
|
+
interface FuncParam {
|
|
11
|
+
name?: string;
|
|
12
|
+
type?: FuncParamType;
|
|
13
|
+
required?: boolean;
|
|
14
|
+
description?: string;
|
|
15
|
+
asyncFeatures?: number;
|
|
16
|
+
depends?: {
|
|
17
|
+
[name: string]: ToolFunc;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
interface FuncParams {
|
|
21
|
+
[name: string]: FuncParam | FuncParamType;
|
|
22
|
+
}
|
|
23
|
+
type TFunc = (this: ToolFunc, ...params: any[]) => any;
|
|
24
|
+
interface BaseFuncItem {
|
|
25
|
+
name?: string;
|
|
26
|
+
params?: FuncParams | FuncParam[];
|
|
27
|
+
result?: string;
|
|
28
|
+
scope?: any;
|
|
29
|
+
tags?: string | string[];
|
|
30
|
+
setup?: (this: ToolFunc, options?: FuncItem) => void;
|
|
31
|
+
isApi?: boolean;
|
|
32
|
+
stream?: boolean;
|
|
33
|
+
}
|
|
34
|
+
interface FuncItem extends BaseFuncItem {
|
|
35
|
+
func?: TFunc;
|
|
36
|
+
}
|
|
37
|
+
interface BaseFunc extends BaseFuncItem {
|
|
38
|
+
func(...params: any): any;
|
|
39
|
+
}
|
|
40
|
+
interface Funcs {
|
|
41
|
+
[name: string]: ToolFunc;
|
|
42
|
+
}
|
|
43
|
+
interface ToolFuncPackage {
|
|
44
|
+
name: string;
|
|
45
|
+
register: (data?: any) => void;
|
|
46
|
+
unregister?: () => void;
|
|
47
|
+
}
|
|
48
|
+
declare interface ToolFunc extends BaseFunc {
|
|
49
|
+
[name: string]: any;
|
|
50
|
+
}
|
|
51
|
+
declare class ToolFunc extends AdvancePropertyManager {
|
|
52
|
+
static items: Funcs;
|
|
53
|
+
static dataPath: string;
|
|
54
|
+
static get(name: string): ToolFunc;
|
|
55
|
+
static list(): Funcs;
|
|
56
|
+
static getByTag(tagName: string): ToolFunc | undefined;
|
|
57
|
+
static getAllByTag(tagName: string): ToolFunc[];
|
|
58
|
+
static hasAsyncFeature(feature: AsyncFeatureBits): boolean;
|
|
59
|
+
static run(name: string, params?: any): Promise<any>;
|
|
60
|
+
static runSync(name: string, params?: any): any;
|
|
61
|
+
static getFunc(name: string): any;
|
|
62
|
+
static runWithPos(name: string, ...params: any[]): Promise<any>;
|
|
63
|
+
static runWithPosSync(name: string, ...params: any[]): any;
|
|
64
|
+
static getFuncWithPos(name: string): any;
|
|
65
|
+
static register(name: string, options: FuncItem): boolean | ToolFunc;
|
|
66
|
+
static register(func: Function, options: FuncItem): boolean | ToolFunc;
|
|
67
|
+
static register(name: string | ToolFunc | Function | FuncItem, options?: FuncItem): boolean | ToolFunc;
|
|
68
|
+
static unregister(name: string): ToolFunc | undefined;
|
|
69
|
+
constructor(name: string | Function | FuncItem, options?: FuncItem | any);
|
|
70
|
+
register(): boolean | ToolFunc;
|
|
71
|
+
unregister(): any;
|
|
72
|
+
arr2ObjParams(params: any[]): any[];
|
|
73
|
+
obj2ArrParams(params?: any): any[];
|
|
74
|
+
runSync(params?: any): any;
|
|
75
|
+
run(params?: any): Promise<any>;
|
|
76
|
+
runAs(name: string, params?: any): Promise<any>;
|
|
77
|
+
runAsSync(name: string, params?: any): any;
|
|
78
|
+
getFunc(name?: string): any;
|
|
79
|
+
runWithPosSync(...params: any[]): any;
|
|
80
|
+
runWithPosAsSync(name: string, ...params: any[]): any;
|
|
81
|
+
runWithPos(...params: any[]): Promise<any>;
|
|
82
|
+
runWithPosAs(name: string, ...params: any[]): Promise<any>;
|
|
83
|
+
getFuncWithPos(name?: string): any;
|
|
84
|
+
hasAsyncFeature(feature: AsyncFeatureBits): boolean;
|
|
85
|
+
isStream(params: any): boolean | undefined;
|
|
86
|
+
}
|
|
87
|
+
declare const ToolFuncSchema: {
|
|
88
|
+
name: {
|
|
89
|
+
type: string;
|
|
90
|
+
};
|
|
91
|
+
description: {
|
|
92
|
+
type: string;
|
|
93
|
+
};
|
|
94
|
+
func: {
|
|
95
|
+
type: string;
|
|
96
|
+
assign(value: Function | string, dest: ToolFunc, src?: ToolFunc, name?: string, options?: any): string | Function;
|
|
97
|
+
};
|
|
98
|
+
params: {
|
|
99
|
+
type: string;
|
|
100
|
+
};
|
|
101
|
+
result: {
|
|
102
|
+
type: string;
|
|
103
|
+
};
|
|
104
|
+
setup: {
|
|
105
|
+
type: string;
|
|
106
|
+
};
|
|
107
|
+
depends: {
|
|
108
|
+
type: string;
|
|
109
|
+
exported: boolean;
|
|
110
|
+
};
|
|
111
|
+
tags: {
|
|
112
|
+
type: string[];
|
|
113
|
+
};
|
|
114
|
+
isApi: {
|
|
115
|
+
type: string;
|
|
116
|
+
};
|
|
117
|
+
stream: {
|
|
118
|
+
type: string;
|
|
119
|
+
};
|
|
120
|
+
asyncFeatures: {
|
|
121
|
+
type: string;
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
declare const PASSING_SCORE = 0.618;
|
|
126
|
+
declare const ActionNames: readonly ["get", "post", "put", "delete", "patch", "list", "res"];
|
|
127
|
+
type ActionName = typeof ActionNames[number];
|
|
128
|
+
type AIModelNameRuleFn = (name: string) => string | RegExpExecArray | undefined;
|
|
129
|
+
type AIModelNameRule = string | RegExp | AIModelNameRuleFn;
|
|
130
|
+
type AIModelNameRules = AIModelNameRule | AIModelNameRule[];
|
|
131
|
+
declare const RemoteToolFuncSchema: {
|
|
132
|
+
apiRoot: {
|
|
133
|
+
type: string;
|
|
134
|
+
get(this: any): any;
|
|
135
|
+
set(this: any, value: string): void;
|
|
136
|
+
};
|
|
137
|
+
action: {
|
|
138
|
+
type: string;
|
|
139
|
+
assign(value: ActionName, dest: any, src?: any, name?: string, options?: any): "get" | "post" | "put" | "delete" | "patch" | "list" | "res";
|
|
140
|
+
};
|
|
141
|
+
fetchOptions: {
|
|
142
|
+
type: string;
|
|
143
|
+
};
|
|
144
|
+
allowExportFunc: {
|
|
145
|
+
type: string;
|
|
146
|
+
};
|
|
147
|
+
};
|
|
148
|
+
interface RemoteFuncItem extends BaseFuncItem {
|
|
149
|
+
apiRoot?: string;
|
|
150
|
+
action?: ActionName;
|
|
151
|
+
fetchOptions?: any;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
declare class Deque<T = any> extends Array<T> {
|
|
155
|
+
private _capacity;
|
|
156
|
+
private _length;
|
|
157
|
+
private _front;
|
|
158
|
+
private _disableAutoResize?;
|
|
159
|
+
constructor(capacity?: number | T[], disableAutoResize?: boolean);
|
|
160
|
+
push(item: T): number;
|
|
161
|
+
unshift(item: T): number;
|
|
162
|
+
/**
|
|
163
|
+
* Removes and returns the element at the back of the deque.
|
|
164
|
+
*
|
|
165
|
+
* @param skipNull When `true`, skips trailing `null`/`undefined` values until a valid element is found or all elements are processed.
|
|
166
|
+
* @returns The removed element, or `undefined` if the deque is empty or all elements are skipped.
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* // Normal pop without skipping
|
|
170
|
+
* const deque = new Deque([1, 2, 3]);
|
|
171
|
+
* deque.pop(); // 3
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
* // Skipping null values
|
|
175
|
+
* const nullDeque = new Deque([null, 4, null]);
|
|
176
|
+
* nullDeque.pop(true); // 4
|
|
177
|
+
* nullDeque.pop(true); // undefined (skipped remaining nulls)
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
* // Mixed elements with skip
|
|
181
|
+
* const mixedDeque = new Deque([5, null, 6, null]);
|
|
182
|
+
* mixedDeque.pop(true); // 6
|
|
183
|
+
* mixedDeque.pop(false); // null (explicitly not skipping)
|
|
184
|
+
*/
|
|
185
|
+
pop(skipNull?: boolean): T | undefined;
|
|
186
|
+
/**
|
|
187
|
+
* Removes and returns the element at the front of the deque.
|
|
188
|
+
*
|
|
189
|
+
* @param skipNull When `true`, skips leading `null`/`undefined` values until a valid element is found or all elements are processed.
|
|
190
|
+
* @returns The removed element, or `undefined` if the deque is empty or all elements are skipped.
|
|
191
|
+
*
|
|
192
|
+
* @example
|
|
193
|
+
* // Normal shift without skipping
|
|
194
|
+
* const deque = new Deque([1, 2, 3]);
|
|
195
|
+
* deque.shift(); // 1
|
|
196
|
+
*
|
|
197
|
+
* @example
|
|
198
|
+
* // Skipping null values
|
|
199
|
+
* const nullDeque = new Deque([null, 4, null]);
|
|
200
|
+
* nullDeque.shift(true); // 4
|
|
201
|
+
* nullDeque.shift(true); // undefined (skipped remaining nulls)
|
|
202
|
+
*
|
|
203
|
+
* @example
|
|
204
|
+
* // Mixed elements with skip
|
|
205
|
+
* const mixedDeque = new Deque([null, 5, null, 6]);
|
|
206
|
+
* mixedDeque.shift(true); // 5
|
|
207
|
+
* mixedDeque.shift(false); // null (explicitly not skipping)
|
|
208
|
+
*/
|
|
209
|
+
shift(skipNull?: boolean): T | undefined;
|
|
210
|
+
/**
|
|
211
|
+
* Gets the number of elements in the deque.
|
|
212
|
+
*
|
|
213
|
+
* @returns The current count of elements in the deque.
|
|
214
|
+
*
|
|
215
|
+
* @example
|
|
216
|
+
* const deque = new Deque([1, 2, 3]);
|
|
217
|
+
* console.log(deque.size); // 3
|
|
218
|
+
*
|
|
219
|
+
* @important
|
|
220
|
+
* Do NOT use the native `Array.length` property. The Deque implementation uses a circular buffer with capacity management, so the native `length` reflects the underlying array capacity, not the actual element count. Always use `size` to get the correct element count.
|
|
221
|
+
*/
|
|
222
|
+
get size(): number;
|
|
223
|
+
get(index: number): T | undefined;
|
|
224
|
+
peekBack(): T | undefined;
|
|
225
|
+
peekFront(): T | undefined;
|
|
226
|
+
clear(): void;
|
|
227
|
+
isEmpty(): boolean;
|
|
228
|
+
/**
|
|
229
|
+
* Removes the element at the specified index.
|
|
230
|
+
* @param index Logical index position (0 represents the front, length-1 represents the back)
|
|
231
|
+
* @returns The removed element
|
|
232
|
+
*/
|
|
233
|
+
removeAt(index: number): T | undefined;
|
|
234
|
+
private checkCapacity;
|
|
235
|
+
private resizeTo;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
declare const DefaultAsyncSemaphoreCapacity = 32;
|
|
239
|
+
type SemaphoreIsReadyFuncType = () => Promise<boolean> | boolean;
|
|
240
|
+
interface BinarySemaphoreOptions {
|
|
241
|
+
initFn?: () => any;
|
|
242
|
+
pauseFn?: () => void;
|
|
243
|
+
resumeFn?: () => void;
|
|
244
|
+
capacity?: number;
|
|
245
|
+
}
|
|
246
|
+
interface BinarySemaphoreAcquireOptions {
|
|
247
|
+
signal?: AbortSignal;
|
|
248
|
+
[n: string]: any;
|
|
249
|
+
}
|
|
250
|
+
interface BinarySemaphoreReleaseOptions {
|
|
251
|
+
token?: any;
|
|
252
|
+
[n: string]: any;
|
|
253
|
+
}
|
|
254
|
+
interface BinarySemaphoreReleaserFunc extends BinarySemaphoreReleaseOptions {
|
|
255
|
+
(): void;
|
|
256
|
+
}
|
|
257
|
+
interface SemaphoreOptions extends BinarySemaphoreOptions {
|
|
258
|
+
maxConcurrency?: number;
|
|
259
|
+
isReadyFn?: SemaphoreIsReadyFuncType;
|
|
260
|
+
}
|
|
261
|
+
interface SemaphoreTaskItem extends BinarySemaphoreAcquireOptions {
|
|
262
|
+
resolve: (value: any) => void;
|
|
263
|
+
reject: (reason?: any) => void;
|
|
264
|
+
token?: any;
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* A binary semaphore implementation for managing concurrency in asynchronous operations.
|
|
268
|
+
* Unlike a general semaphore, a binary semaphore allows only one caller to acquire the semaphore at a time.
|
|
269
|
+
* It provides methods to acquire, release, and manage waiting tasks efficiently.
|
|
270
|
+
*
|
|
271
|
+
* Example usage:
|
|
272
|
+
*
|
|
273
|
+
* ```typescript
|
|
274
|
+
* const semaphore = new Semaphore(5); // Allows 5 concurrent operations.
|
|
275
|
+
*
|
|
276
|
+
* const semaphore = new Semaphore(
|
|
277
|
+
* 4, // Allow 4 concurrent async calls
|
|
278
|
+
* {
|
|
279
|
+
* capacity: 100 // Prealloc space for 100 tokens
|
|
280
|
+
* }
|
|
281
|
+
* );
|
|
282
|
+
*
|
|
283
|
+
* async function fetchData(x) {
|
|
284
|
+
* await semaphore.acquire()
|
|
285
|
+
* try {
|
|
286
|
+
* console.log(semaphore.pendingCount + ' calls to fetch are waiting')
|
|
287
|
+
* // ... do some async stuff with x
|
|
288
|
+
* } finally {
|
|
289
|
+
* semaphore.release();
|
|
290
|
+
* }
|
|
291
|
+
* }
|
|
292
|
+
*
|
|
293
|
+
* const data = await Promise.all(array.map(fetchData));
|
|
294
|
+
* ```
|
|
295
|
+
*/
|
|
296
|
+
declare class BinarySemaphore {
|
|
297
|
+
readonly waiting: Deque<SemaphoreTaskItem | undefined>;
|
|
298
|
+
protected free: any;
|
|
299
|
+
protected emitter: EventEmitter;
|
|
300
|
+
protected useDefaultTokens: boolean;
|
|
301
|
+
protected pauseFn?: () => void;
|
|
302
|
+
protected resumeFn?: () => void;
|
|
303
|
+
protected initTokenFn: (token?: any) => void;
|
|
304
|
+
protected paused: boolean;
|
|
305
|
+
protected _activeCount: number;
|
|
306
|
+
/**
|
|
307
|
+
* Creates a binary semaphore object for managing concurrency in asynchronous operations.
|
|
308
|
+
*
|
|
309
|
+
* @param options.initFn Function that is used to initialize the tokens used to manage the semaphore. The default is () => '1'.
|
|
310
|
+
* @param options.pauseFn An optional fuction that is called to opportunistically request pausing the the incoming stream of data,
|
|
311
|
+
* instead of piling up waiting promises and possibly running out of memory. See examples/pausing.js.
|
|
312
|
+
* @param options.resumeFn An optional function that is called when there is room again to accept new waiters on the semaphore.
|
|
313
|
+
* This function must be declared if a pauseFn is declared.
|
|
314
|
+
* @param options.capacity Sets the size of the preallocated waiting list inside the semaphore.
|
|
315
|
+
* This is typically used by high performance where the developer can make a rough estimate of the number of concurrent users of a semaphore.
|
|
316
|
+
*
|
|
317
|
+
* ```ts
|
|
318
|
+
* const readline = require('readline');
|
|
319
|
+
*
|
|
320
|
+
* const rl = readline.createInterface({
|
|
321
|
+
* input: process.stdin,
|
|
322
|
+
* output: process.stdout,
|
|
323
|
+
* terminal: false
|
|
324
|
+
* });
|
|
325
|
+
*
|
|
326
|
+
* function pause() {
|
|
327
|
+
* console.log('Pausing the stream');
|
|
328
|
+
* rl.pause();
|
|
329
|
+
* }
|
|
330
|
+
*
|
|
331
|
+
* function resume() {
|
|
332
|
+
* console.log('Resuming the stream');
|
|
333
|
+
* rl.resume();
|
|
334
|
+
* }
|
|
335
|
+
*
|
|
336
|
+
* const s = new BinarySemaphore({ pauseFn: pause, resumeFn: resume });
|
|
337
|
+
*
|
|
338
|
+
* async function parse(line) {
|
|
339
|
+
* await s.acquire();
|
|
340
|
+
*
|
|
341
|
+
* console.log(line);
|
|
342
|
+
*
|
|
343
|
+
* s.release();
|
|
344
|
+
* }
|
|
345
|
+
*
|
|
346
|
+
* rl.on('line', line => {
|
|
347
|
+
* parse(line).catch(console.error);
|
|
348
|
+
* });
|
|
349
|
+
* ```
|
|
350
|
+
*
|
|
351
|
+
*/
|
|
352
|
+
constructor(options?: BinarySemaphoreOptions);
|
|
353
|
+
initFree(options?: BinarySemaphoreOptions): void;
|
|
354
|
+
onReleased(options?: BinarySemaphoreReleaseOptions): void;
|
|
355
|
+
init(options: BinarySemaphoreOptions): void;
|
|
356
|
+
_newReleaser(options?: BinarySemaphoreReleaseOptions): BinarySemaphoreReleaserFunc;
|
|
357
|
+
_dispatchTask(task: SemaphoreTaskItem, options?: BinarySemaphoreReleaseOptions): void;
|
|
358
|
+
lock(options?: BinarySemaphoreAcquireOptions): any;
|
|
359
|
+
unlock(token?: any): void;
|
|
360
|
+
/**
|
|
361
|
+
* Attempt to acquire a token from the semaphore, if one is available immediately. Otherwise, return undefined.
|
|
362
|
+
*
|
|
363
|
+
* @return Returns a token if the semaphore is not full; otherwise, returns `undefined`.
|
|
364
|
+
*/
|
|
365
|
+
tryAcquire(options?: BinarySemaphoreAcquireOptions): any | undefined;
|
|
366
|
+
/**
|
|
367
|
+
* 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.
|
|
368
|
+
* @param options.signal An optional AbortSignal to abort the acquisition process. If aborted, the promise will reject with an AbortError.
|
|
369
|
+
* @return A promise that resolves to a release function when a token is acquired. If the semaphore is full, the caller will be added to a waiting queue.
|
|
370
|
+
*/
|
|
371
|
+
acquire(options?: BinarySemaphoreAcquireOptions): Promise<BinarySemaphoreReleaserFunc>;
|
|
372
|
+
/**
|
|
373
|
+
* Releases the semaphore, incrementing the number of free execution slots. If there are tasks in the waiting queue, the next task will be dispatched.
|
|
374
|
+
* @param options.token Optional token returned by `acquire()` when using a custom `initFn`. If provided, it will be used to unlock the semaphore.
|
|
375
|
+
*/
|
|
376
|
+
release(options?: BinarySemaphoreReleaseOptions): void;
|
|
377
|
+
/**
|
|
378
|
+
* 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.
|
|
379
|
+
*/
|
|
380
|
+
drain(): Promise<any[]>;
|
|
381
|
+
abort(reason?: any): void;
|
|
382
|
+
/**
|
|
383
|
+
* Get the total count of all active operations.
|
|
384
|
+
*
|
|
385
|
+
* This method returns the number of operations that are either:
|
|
386
|
+
* - Waiting in the queue to acquire the semaphore (`pendingCount`).
|
|
387
|
+
* - Already acquired the semaphore but have not yet released it.
|
|
388
|
+
*
|
|
389
|
+
* @returns {number} The total count of active operations, including both waiting and ongoing tasks.
|
|
390
|
+
*/
|
|
391
|
+
get activeCount(): number;
|
|
392
|
+
/**
|
|
393
|
+
* Get the number of callers waiting on the semaphore, i.e. the number of pending promises.
|
|
394
|
+
*
|
|
395
|
+
* @returns The number of waiters in the waiting list.
|
|
396
|
+
*/
|
|
397
|
+
get pendingCount(): number;
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* A Semaphore implementation for managing concurrency in asynchronous operations.
|
|
401
|
+
* Semaphores allow a fixed number of resources to be accessed concurrently.
|
|
402
|
+
* This class extends BinarySemaphore and adds support for a maximum concurrency limit and an optional readiness check.
|
|
403
|
+
*
|
|
404
|
+
* Example usage:
|
|
405
|
+
*
|
|
406
|
+
* ```typescript
|
|
407
|
+
* const semaphore = new Semaphore(5); // Allows 5 concurrent operations.
|
|
408
|
+
*
|
|
409
|
+
* const semaphore = new Semaphore(
|
|
410
|
+
* 4, // Allow 4 concurrent async calls
|
|
411
|
+
* {
|
|
412
|
+
* capacity: 100, // Prealloc space for 100 tokens
|
|
413
|
+
* isReadyFn: async () => {
|
|
414
|
+
* // Check if the system is ready to handle more requests
|
|
415
|
+
* return true;
|
|
416
|
+
* },
|
|
417
|
+
* pauseFn: () => {
|
|
418
|
+
* console.log('Pausing the stream');
|
|
419
|
+
* },
|
|
420
|
+
* resumeFn: () => {
|
|
421
|
+
* console.log('Resuming the stream');
|
|
422
|
+
* }
|
|
423
|
+
* }
|
|
424
|
+
* );
|
|
425
|
+
*
|
|
426
|
+
* async function fetchData(x) {
|
|
427
|
+
* await semaphore.acquire()
|
|
428
|
+
* try {
|
|
429
|
+
* console.log(semaphore.pendingCount() + ' calls to fetch are waiting')
|
|
430
|
+
* // ... do some async stuff with x
|
|
431
|
+
* } finally {
|
|
432
|
+
* semaphore.release();
|
|
433
|
+
* }
|
|
434
|
+
* }
|
|
435
|
+
*
|
|
436
|
+
* const data = await Promise.all(array.map(fetchData));
|
|
437
|
+
* ```
|
|
438
|
+
*/
|
|
439
|
+
declare class Semaphore extends BinarySemaphore {
|
|
440
|
+
readonly maxConcurrency: number;
|
|
441
|
+
protected free: Deque<any>;
|
|
442
|
+
private isReady?;
|
|
443
|
+
/**
|
|
444
|
+
* Creates a semaphore object. The first argument is the maximum concurrently number and the second argument is optional.
|
|
445
|
+
*
|
|
446
|
+
* @param maxConcurrency The maximum number of callers allowed to acquire the semaphore concurrently.
|
|
447
|
+
* @param options.initFn Function that is used to initialize the tokens used to manage the semaphore. The default is () => '1'.
|
|
448
|
+
* @param options.pauseFn An optional function that is called to opportunistically request pausing the incoming stream of data,
|
|
449
|
+
* instead of piling up waiting promises and possibly running out of memory. See examples/pausing.js.
|
|
450
|
+
* @param options.resumeFn An optional function that is called when there is room again to accept new waiters on the semaphore.
|
|
451
|
+
* This function must be declared if a pauseFn is declared.
|
|
452
|
+
* @param options.capacity Sets the size of the preallocated waiting list inside the semaphore.
|
|
453
|
+
* This is typically used by high performance where the developer can make a rough estimate of the number of concurrent users of a semaphore.
|
|
454
|
+
* @param options.isReadyFn An optional function that returns a boolean or a promise that resolves to a boolean indicating whether the semaphore is ready to accept new requests.
|
|
455
|
+
*/
|
|
456
|
+
constructor(maxConcurrency: number | SemaphoreOptions, options?: SemaphoreOptions);
|
|
457
|
+
initFree(options: SemaphoreOptions): void;
|
|
458
|
+
tryAcquire(options?: BinarySemaphoreAcquireOptions): Promise<any | undefined> | any | undefined;
|
|
459
|
+
unlock(token?: any): void;
|
|
460
|
+
lock(options?: BinarySemaphoreAcquireOptions): any;
|
|
461
|
+
drain(): Promise<any[]>;
|
|
462
|
+
}
|
|
463
|
+
/**
|
|
464
|
+
* 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.
|
|
465
|
+
*
|
|
466
|
+
* @param rps
|
|
467
|
+
* @param options.timeUnit The `timeUnit` is an optional argument setting the width of the rate limiting window in milliseconds.
|
|
468
|
+
* The default `timeUnit` is 1000 ms, therefore making the rps argument act as requests per second limit.
|
|
469
|
+
* @param options.uniformDistribution The `uniformDistribution` argument enforces a discrete uniform distribution over time,
|
|
470
|
+
* instead of the default that allows hitting the function rps time and then pausing for timeWindow milliseconds. Setting
|
|
471
|
+
* the `uniformDistribution` option is mainly useful in a situation where the flow of rate limit function calls is continuous
|
|
472
|
+
* and and occuring faster than timeUnit (e.g. reading a file) and not enabling it would cause the maximum number of calls to
|
|
473
|
+
* resolve immediately (thus exhaust the limit immediately) and therefore the next bunch calls would need to wait for timeWindow
|
|
474
|
+
* milliseconds. However if the flow is sparse then this option may make the code run slower with no advantages.
|
|
475
|
+
*
|
|
476
|
+
* Examples:
|
|
477
|
+
*
|
|
478
|
+
* ```ts
|
|
479
|
+
* async function f() {
|
|
480
|
+
* const lim = RateLimit(5); // rps
|
|
481
|
+
*
|
|
482
|
+
* for (let i = 0; i < n; i++) {
|
|
483
|
+
* await lim();
|
|
484
|
+
* // ... do something async
|
|
485
|
+
* }
|
|
486
|
+
* }
|
|
487
|
+
* ```
|
|
488
|
+
*
|
|
489
|
+
*
|
|
490
|
+
*/
|
|
491
|
+
declare function RateLimit(rps: number, { timeUnit, uniformDistribution, }?: {
|
|
492
|
+
timeUnit?: number;
|
|
493
|
+
uniformDistribution?: boolean;
|
|
494
|
+
}): () => Promise<void>;
|
|
495
|
+
|
|
496
|
+
declare const ToolAsyncMultiTaskBit = 0;
|
|
497
|
+
declare const ToolAsyncCancelableBit = 1;
|
|
498
|
+
declare const ToolAsyncPriorityBit = 2;
|
|
499
|
+
declare enum AsyncFeatureBits {
|
|
500
|
+
MultiTask = 0,
|
|
501
|
+
Cancelable = 1,
|
|
502
|
+
Priority = 2
|
|
503
|
+
}
|
|
504
|
+
declare enum AsyncFeatures {
|
|
505
|
+
MultiTask = 1,// B0001
|
|
506
|
+
Cancelable = 2,// B010
|
|
507
|
+
Priority = 4
|
|
508
|
+
}
|
|
509
|
+
type AsyncTaskId = string | number;
|
|
510
|
+
interface CancelableAbilityOptions extends AbilityOptions {
|
|
511
|
+
asyncFeatures?: AsyncFeatures;
|
|
512
|
+
maxTaskConcurrency?: number;
|
|
513
|
+
isReadyFn?: SemaphoreIsReadyFuncType;
|
|
514
|
+
}
|
|
515
|
+
declare class TaskAbortController extends AbortController {
|
|
516
|
+
id?: AsyncTaskId;
|
|
517
|
+
timeoutId?: any;
|
|
518
|
+
streamController?: ReadableStreamDefaultController;
|
|
519
|
+
parent: CancelableAbility;
|
|
520
|
+
constructor(parent: CancelableAbility);
|
|
521
|
+
abort(reason?: string | Error | CommonError, data?: any): void;
|
|
522
|
+
throwRejected(alreadyRejected?: boolean): true | undefined;
|
|
523
|
+
}
|
|
524
|
+
interface TaskAbortControllers {
|
|
525
|
+
[k: AsyncTaskId]: TaskAbortController | undefined;
|
|
526
|
+
}
|
|
527
|
+
interface TaskPromise<T = any> extends Promise<T> {
|
|
528
|
+
task?: TaskAbortController;
|
|
529
|
+
}
|
|
530
|
+
declare interface CancelableAbility {
|
|
531
|
+
_asyncFeatures?: number;
|
|
532
|
+
_maxTaskConcurrency: number | undefined;
|
|
533
|
+
_isReadyFn?: SemaphoreIsReadyFuncType;
|
|
534
|
+
[name: string]: any;
|
|
535
|
+
}
|
|
536
|
+
declare class CancelableAbility {
|
|
537
|
+
generateAsyncTaskId: (taskId?: AsyncTaskId, aborters?: TaskAbortControllers) => AsyncTaskId;
|
|
538
|
+
cleanMultiTaskAborter: (id: AsyncTaskId, aborters: TaskAbortControllers) => void;
|
|
539
|
+
__task_aborter: TaskAbortController | TaskAbortControllers | undefined;
|
|
540
|
+
__task_semaphore: Semaphore | undefined;
|
|
541
|
+
get maxTaskConcurrency(): number | undefined;
|
|
542
|
+
get semaphore(): Semaphore | undefined;
|
|
543
|
+
getSemaphore(isReadyFn?: SemaphoreIsReadyFuncType | undefined): Semaphore | undefined;
|
|
544
|
+
static hasAsyncFeature(feature: AsyncFeatureBits): boolean;
|
|
545
|
+
hasAsyncFeature(feature: AsyncFeatureBits): boolean;
|
|
546
|
+
isAborted(taskId?: AsyncTaskId): boolean;
|
|
547
|
+
getRunningTask(taskId?: AsyncTaskId): TaskAbortController | undefined;
|
|
548
|
+
getRunningTaskCount(): number;
|
|
549
|
+
_generateAsyncTaskId(taskId?: AsyncTaskId, aborters?: TaskAbortControllers): AsyncTaskId;
|
|
550
|
+
$generateAsyncTaskId(taskId?: AsyncTaskId, aborters?: TaskAbortControllers): AsyncTaskId | undefined;
|
|
551
|
+
createAborter(params?: any, taskId?: AsyncTaskId, raiseError?: boolean): TaskAbortController;
|
|
552
|
+
$cleanMultiTaskAborter(id: AsyncTaskId, aborters: TaskAbortControllers): void;
|
|
553
|
+
cleanTaskAborter(aborter: TaskAbortController): void;
|
|
554
|
+
_cleanMultiTaskAborter(id: AsyncTaskId, aborters: TaskAbortControllers): void;
|
|
555
|
+
createTaskPromise<Output = any>(runTask: (params: Record<string, any>, aborter: TaskAbortController) => Promise<Output>, params: Record<string, any>, options?: {
|
|
556
|
+
taskId?: AsyncTaskId;
|
|
557
|
+
raiseError?: boolean;
|
|
558
|
+
}): TaskPromise<Output>;
|
|
559
|
+
runAsyncCancelableTask<Output = any>(params: Record<string, any> | undefined, runTask: (params: Record<string, any>, aborter: TaskAbortController) => Promise<Output>, options?: {
|
|
560
|
+
taskId?: AsyncTaskId;
|
|
561
|
+
raiseError?: boolean;
|
|
562
|
+
isReadyFn?: SemaphoreIsReadyFuncType;
|
|
563
|
+
}): TaskPromise<Output>;
|
|
564
|
+
abort(reason?: string, data?: any): void;
|
|
565
|
+
}
|
|
566
|
+
declare const makeToolFuncCancelable: <T extends Function | (new (...args: any[]) => any)>(targetClass?: T | undefined, options?: AbilityOptions) => T & typeof CancelableAbility & (T extends new (...args: any[]) => any ? InstanceType<T> : T) & CancelableAbility;
|
|
567
|
+
|
|
568
|
+
type Events = (string | RegExp)[];
|
|
569
|
+
type Client = {
|
|
570
|
+
req: IncomingMessage;
|
|
571
|
+
res: ServerResponse;
|
|
572
|
+
events?: Events;
|
|
573
|
+
};
|
|
574
|
+
declare const SSEChannelAlreadyClosedErrCode = 498;
|
|
575
|
+
/**
|
|
576
|
+
* A class for creating Server-Sent Events (SSE) channels.
|
|
577
|
+
* @example
|
|
578
|
+
* const sseChannel = new SSEChannel({ pingInterval: 5000 })
|
|
579
|
+
* sseChannel.publish('Hello, world!', 'greeting')
|
|
580
|
+
*/
|
|
581
|
+
declare class SSEChannel {
|
|
582
|
+
_active: boolean;
|
|
583
|
+
clients: Set<Client>;
|
|
584
|
+
messages: Record<string, any>[];
|
|
585
|
+
nextID: number;
|
|
586
|
+
options: Record<string, any>;
|
|
587
|
+
pingTimer?: NodeJS.Timeout;
|
|
588
|
+
get active(): boolean;
|
|
589
|
+
set active(v: boolean);
|
|
590
|
+
/**
|
|
591
|
+
* Creates a new SSE channel.
|
|
592
|
+
* @param options - The options for the SSE channel.
|
|
593
|
+
*/
|
|
594
|
+
constructor(options?: Record<string, any>);
|
|
595
|
+
/**
|
|
596
|
+
* Publishes a message to the SSE channel.
|
|
597
|
+
* @param {string | Record<string, any>} data - The data to send. It can be a string or an object.
|
|
598
|
+
* @param {string} eventName - The name of the event.
|
|
599
|
+
* @returns {number | undefined} - Returns the ID of the message.
|
|
600
|
+
* @throws Will throw an error if the channel is closed.
|
|
601
|
+
*/
|
|
602
|
+
publish(data?: string | Record<string, any>, eventName?: string): number | undefined;
|
|
603
|
+
/**
|
|
604
|
+
* Subscribes a client to the SSE channel.
|
|
605
|
+
* @param {IncomingMessage} req - The request object.
|
|
606
|
+
* @param {ServerResponse} res - The response object.
|
|
607
|
+
* @param {Events} events - The events to subscribe to.
|
|
608
|
+
* @returns {Client} - Returns the client object.
|
|
609
|
+
* @throws Will throw an error if the channel is closed.
|
|
610
|
+
*/
|
|
611
|
+
subscribe(req: IncomingMessage, res: ServerResponse, events?: Events): {
|
|
612
|
+
req: IncomingMessage;
|
|
613
|
+
res: ServerResponse<IncomingMessage>;
|
|
614
|
+
events: Events | undefined;
|
|
615
|
+
};
|
|
616
|
+
/**
|
|
617
|
+
* Unsubscribes a client from the SSE channel.
|
|
618
|
+
* @param {Client} c - The client to unsubscribe.
|
|
619
|
+
*/
|
|
620
|
+
unsubscribe(c: Client): void;
|
|
621
|
+
clearClients(): void;
|
|
622
|
+
/**
|
|
623
|
+
* Lists the clients connected to the SSE channel grouped by IP address.
|
|
624
|
+
* @returns - Returns an object where the keys are the IP addresses and the values are the number of clients connected from each IP.
|
|
625
|
+
*/
|
|
626
|
+
listClients(): Record<string, number>;
|
|
627
|
+
/**
|
|
628
|
+
* Gets the number of clients subscribed to the SSE channel.
|
|
629
|
+
* @returns - Returns the number of clients.
|
|
630
|
+
*/
|
|
631
|
+
getSubscriberCount(): number;
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
declare global {
|
|
635
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- It has to be an `interface` so that it can be merged.
|
|
636
|
+
interface SymbolConstructor {
|
|
637
|
+
readonly observable: symbol;
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
interface ClientFuncItem extends RemoteFuncItem {
|
|
642
|
+
}
|
|
643
|
+
declare interface ClientTools extends ClientFuncItem {
|
|
644
|
+
[name: string]: any;
|
|
645
|
+
}
|
|
646
|
+
declare class ClientTools extends ToolFunc {
|
|
647
|
+
apiRoot: string | undefined;
|
|
648
|
+
private static _apiRoot?;
|
|
649
|
+
static get apiRoot(): string | undefined;
|
|
650
|
+
static setApiRoot(v: string): void;
|
|
651
|
+
static loadFrom(): Promise<void>;
|
|
652
|
+
static loadFromSync(items: Funcs): void;
|
|
653
|
+
static fetch(name: string, objParam?: any): Promise<any>;
|
|
654
|
+
getUrlParams(objParam: any): string;
|
|
655
|
+
fetch(objParam?: any, act?: ActionName, subName?: any): Promise<Response>;
|
|
656
|
+
errorFrom(res: Response): Promise<_isdk_common_error.CommonError>;
|
|
657
|
+
func(objParam: any): Promise<any>;
|
|
658
|
+
}
|
|
659
|
+
declare const ClientToolFuncSchema: {
|
|
660
|
+
apiRoot: {
|
|
661
|
+
type: string;
|
|
662
|
+
get(this: any): any;
|
|
663
|
+
set(this: any, value: string): void;
|
|
664
|
+
};
|
|
665
|
+
action: {
|
|
666
|
+
type: string;
|
|
667
|
+
assign(value: ActionName, dest: any, src?: any, name?: string, options?: any): "get" | "post" | "put" | "delete" | "patch" | "list" | "res";
|
|
668
|
+
};
|
|
669
|
+
fetchOptions: {
|
|
670
|
+
type: string;
|
|
671
|
+
};
|
|
672
|
+
allowExportFunc: {
|
|
673
|
+
type: string;
|
|
674
|
+
};
|
|
675
|
+
};
|
|
676
|
+
|
|
677
|
+
/**
|
|
678
|
+
* Convention: Always pass _req, _res
|
|
679
|
+
*/
|
|
680
|
+
interface ServerFuncParams {
|
|
681
|
+
_req?: IncomingMessage;
|
|
682
|
+
_res?: ServerResponse;
|
|
683
|
+
[name: string]: any;
|
|
684
|
+
}
|
|
685
|
+
interface ServerFuncItem extends RemoteFuncItem {
|
|
686
|
+
allowExportFunc?: boolean;
|
|
687
|
+
}
|
|
688
|
+
declare interface ServerTools extends ServerFuncItem {
|
|
689
|
+
[name: string]: any;
|
|
690
|
+
}
|
|
691
|
+
declare class ServerTools extends ToolFunc {
|
|
692
|
+
private static _apiRoot?;
|
|
693
|
+
static get apiRoot(): string | undefined;
|
|
694
|
+
static setApiRoot(v: string): void;
|
|
695
|
+
static toJSON(): {
|
|
696
|
+
[name: string]: ServerTools;
|
|
697
|
+
};
|
|
698
|
+
func({}: {}): Promise<any> | any;
|
|
699
|
+
}
|
|
700
|
+
declare const ServerToolFuncSchema: {
|
|
701
|
+
apiRoot: {
|
|
702
|
+
type: string;
|
|
703
|
+
get(this: any): any;
|
|
704
|
+
set(this: any, value: string): void;
|
|
705
|
+
};
|
|
706
|
+
action: {
|
|
707
|
+
type: string;
|
|
708
|
+
assign(value: ActionName, dest: any, src?: any, name?: string, options?: any): "get" | "post" | "put" | "delete" | "patch" | "list" | "res";
|
|
709
|
+
};
|
|
710
|
+
fetchOptions: {
|
|
711
|
+
type: string;
|
|
712
|
+
};
|
|
713
|
+
allowExportFunc: {
|
|
714
|
+
type: string;
|
|
715
|
+
};
|
|
716
|
+
};
|
|
717
|
+
|
|
718
|
+
declare class EventToolFunc extends ToolFunc {
|
|
719
|
+
_emitter: EventEmitter;
|
|
720
|
+
description: string;
|
|
721
|
+
result: string;
|
|
722
|
+
get emitter(): EventEmitter;
|
|
723
|
+
func(): EventEmitter;
|
|
724
|
+
}
|
|
725
|
+
declare const event: EventToolFunc;
|
|
726
|
+
|
|
727
|
+
declare const SecondaryCache: typeof Cache;
|
|
728
|
+
declare function _lrucache(this: ToolFunc, { key, value, options }?: {
|
|
729
|
+
key?: string;
|
|
730
|
+
value?: any;
|
|
731
|
+
options?: ICacheOptions | number;
|
|
732
|
+
}): Cache;
|
|
733
|
+
declare function createLRUCache(name: string, options?: ICacheOptions | number): ToolFunc;
|
|
734
|
+
declare const lrucache: ToolFunc;
|
|
735
|
+
|
|
736
|
+
interface RpcMethodsClientFuncParams {
|
|
737
|
+
act?: string;
|
|
738
|
+
[name: string]: any;
|
|
739
|
+
}
|
|
740
|
+
declare class RpcMethodsClientTool extends ClientTools {
|
|
741
|
+
_func(action: ActionName, options: RpcMethodsClientFuncParams): Promise<any>;
|
|
742
|
+
func(options: RpcMethodsClientFuncParams): Promise<any>;
|
|
743
|
+
assignMethods(methods: string[]): void;
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
interface ResClientFuncParams extends RpcMethodsClientFuncParams {
|
|
747
|
+
id?: string | number;
|
|
748
|
+
}
|
|
749
|
+
interface ResClientTools {
|
|
750
|
+
get?({ id }: ResClientFuncParams): any;
|
|
751
|
+
post?(options: ResClientFuncParams): any;
|
|
752
|
+
put?({ id }: ResClientFuncParams): any;
|
|
753
|
+
delete?({ id }: ResClientFuncParams): any;
|
|
754
|
+
list?(options: ResClientFuncParams): any;
|
|
755
|
+
}
|
|
756
|
+
declare class ResClientTools extends RpcMethodsClientTool {
|
|
757
|
+
fetch(options: ResClientFuncParams, action: ActionName): Promise<Response>;
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
interface EventClientFuncParams {
|
|
761
|
+
event?: string | string[];
|
|
762
|
+
data?: any;
|
|
763
|
+
act?: 'sub' | 'pub' | 'unsub' | 'init';
|
|
764
|
+
listener?: (...args: any[]) => void;
|
|
765
|
+
}
|
|
766
|
+
declare class EventClient extends ResClientTools {
|
|
767
|
+
_es: EventSource | undefined;
|
|
768
|
+
_esEvents: string[] | undefined;
|
|
769
|
+
_sseEvents: Record<string, (e: MessageEvent) => void>;
|
|
770
|
+
_forwardEvents: Set<string>;
|
|
771
|
+
get evtSource(): EventSource;
|
|
772
|
+
get active(): boolean;
|
|
773
|
+
set active(v: boolean);
|
|
774
|
+
name: string;
|
|
775
|
+
description: string;
|
|
776
|
+
initEventSource(events?: string | string[]): EventSource;
|
|
777
|
+
esListener(event: MessageEvent): void;
|
|
778
|
+
ebListener: (this: Event, ...data: any[]) => Promise<void>;
|
|
779
|
+
/**
|
|
780
|
+
* subscribe server sent event(SSE)
|
|
781
|
+
* @param events
|
|
782
|
+
*/
|
|
783
|
+
subscribe(events: string | string[]): Promise<any>;
|
|
784
|
+
/**
|
|
785
|
+
* unsubscribe server sent event(SSE)
|
|
786
|
+
* @param events
|
|
787
|
+
*/
|
|
788
|
+
unsubscribe(events: string | string[]): Promise<any>;
|
|
789
|
+
/**
|
|
790
|
+
* forward local event(s) to server
|
|
791
|
+
*
|
|
792
|
+
* subscribe these local events to forward/publish to server
|
|
793
|
+
*
|
|
794
|
+
* Note: pls backendEventable(ClientTools or EventClient) first
|
|
795
|
+
* @param events
|
|
796
|
+
*/
|
|
797
|
+
forwardEvent(events: string | string[]): void;
|
|
798
|
+
/**
|
|
799
|
+
* unforward local event(s) to server
|
|
800
|
+
*
|
|
801
|
+
* unsubscribe these local events not to forward/publish to server
|
|
802
|
+
*
|
|
803
|
+
* Note: pls backendEventable(ClientTools or EventClient) first
|
|
804
|
+
* @param events
|
|
805
|
+
*/
|
|
806
|
+
unforwardEvent(events: string | string[]): void;
|
|
807
|
+
init(events: string | string[]): Promise<any>;
|
|
808
|
+
}
|
|
809
|
+
declare const eventClient: EventClient;
|
|
810
|
+
|
|
811
|
+
interface RpcMethodsServerFuncParams extends ServerFuncParams {
|
|
812
|
+
act?: string;
|
|
813
|
+
}
|
|
814
|
+
interface RpcMethodsServerTool {
|
|
815
|
+
methods: string[];
|
|
816
|
+
}
|
|
817
|
+
declare class RpcMethodsServerTool extends ServerTools {
|
|
818
|
+
static SpecialRpcMethodNames?: string[];
|
|
819
|
+
params: FuncParams;
|
|
820
|
+
get SpecialRpcMethodNames(): any;
|
|
821
|
+
initRpcMethods(methods?: string[]): void;
|
|
822
|
+
constructor(name: string | Function | FuncItem, options?: FuncItem | any);
|
|
823
|
+
cast(key: string, value: any): any;
|
|
824
|
+
getMethodFromParams(params: RpcMethodsServerFuncParams): string | undefined;
|
|
825
|
+
castParams(params: RpcMethodsServerFuncParams): RpcMethodsServerFuncParams;
|
|
826
|
+
func(params: RpcMethodsServerFuncParams): any;
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
interface ResServerFuncParams extends RpcMethodsServerFuncParams {
|
|
830
|
+
id?: string | number;
|
|
831
|
+
val?: any;
|
|
832
|
+
}
|
|
833
|
+
interface ResServerTools {
|
|
834
|
+
get?({ id }: ResServerFuncParams): any;
|
|
835
|
+
post?(options: ResServerFuncParams): any;
|
|
836
|
+
put?({ id }: ResServerFuncParams): any;
|
|
837
|
+
delete?({ id }: ResServerFuncParams): any;
|
|
838
|
+
list?(options?: ResServerFuncParams): any;
|
|
839
|
+
}
|
|
840
|
+
declare class ResServerTools extends RpcMethodsServerTool {
|
|
841
|
+
static SpecialRpcMethodNames: any;
|
|
842
|
+
action: ActionName;
|
|
843
|
+
params: FuncParams;
|
|
844
|
+
constructor(name: string | Function | FuncItem, options?: FuncItem | any);
|
|
845
|
+
getMethodFromParams(params: ResServerFuncParams): string | undefined;
|
|
846
|
+
castParams(params: RpcMethodsServerFuncParams): RpcMethodsServerFuncParams;
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
interface EventServerFuncParams extends ServerFuncParams {
|
|
850
|
+
event?: string | string[];
|
|
851
|
+
data?: any;
|
|
852
|
+
act?: 'sub' | 'pub' | 'unsub';
|
|
853
|
+
}
|
|
854
|
+
declare class EventServer extends ResServerTools {
|
|
855
|
+
static _sse: SSEChannel | undefined;
|
|
856
|
+
static get sse(): SSEChannel;
|
|
857
|
+
name: string;
|
|
858
|
+
description: string;
|
|
859
|
+
result: string;
|
|
860
|
+
depends: {
|
|
861
|
+
"event-bus": EventToolFunc;
|
|
862
|
+
};
|
|
863
|
+
get sse(): any;
|
|
864
|
+
static publish(data: any, event: string): number | undefined;
|
|
865
|
+
static ebListener: (this: Event, ...data: any[]) => void;
|
|
866
|
+
static subscribe(req: IncomingMessage, res: ServerResponse, events?: string[]): {
|
|
867
|
+
req: IncomingMessage;
|
|
868
|
+
res: ServerResponse<IncomingMessage>;
|
|
869
|
+
events: (string | RegExp)[] | undefined;
|
|
870
|
+
};
|
|
871
|
+
static alreadyForward(event: string): true | undefined;
|
|
872
|
+
publishSSE(data: any, event: string): any;
|
|
873
|
+
subscribeSSE(req: IncomingMessage, res: ServerResponse, events?: string | string[]): any;
|
|
874
|
+
forward(events: string | string[]): void;
|
|
875
|
+
unforward(events: string | string[]): void;
|
|
876
|
+
list({ _req, _res, event }: EventServerFuncParams): void;
|
|
877
|
+
$sub({ event }: EventServerFuncParams): {
|
|
878
|
+
event: string | string[];
|
|
879
|
+
} | undefined;
|
|
880
|
+
$unsub({ event }: EventServerFuncParams): {
|
|
881
|
+
event: string | string[];
|
|
882
|
+
} | undefined;
|
|
883
|
+
$publish({ event: events, data }: EventServerFuncParams): {
|
|
884
|
+
event: string[];
|
|
885
|
+
} | undefined;
|
|
886
|
+
isStream(params: ServerFuncParams): boolean;
|
|
887
|
+
}
|
|
888
|
+
declare const eventServer: EventServer;
|
|
889
|
+
|
|
890
|
+
declare function registerCoreTools(): void;
|
|
891
|
+
|
|
892
|
+
export { event as $, type AsyncTaskId as A, type BinarySemaphoreOptions as B, type CancelableAbilityOptions as C, DefaultAsyncSemaphoreCapacity as D, type FuncParams as E, type FuncParamType as F, type TFunc as G, type BaseFuncItem as H, type FuncItem as I, type BaseFunc as J, type Funcs as K, type ToolFuncPackage as L, ToolFunc as M, ToolFuncSchema as N, type ClientFuncItem as O, PASSING_SCORE as P, ClientTools as Q, RemoteToolFuncSchema as R, SSEChannelAlreadyClosedErrCode as S, ToolAsyncMultiTaskBit as T, ClientToolFuncSchema as U, type ServerFuncParams as V, type ServerFuncItem as W, ServerTools as X, ServerToolFuncSchema as Y, registerCoreTools as Z, EventToolFunc as _, type AIModelNameRules as a, SecondaryCache as a0, _lrucache as a1, createLRUCache as a2, lrucache as a3, type EventClientFuncParams as a4, EventClient as a5, eventClient as a6, type EventServerFuncParams as a7, EventServer as a8, eventServer as a9, type ResClientFuncParams as aa, ResClientTools as ab, type ResServerFuncParams as ac, ResServerTools as ad, ActionNames as b, type ActionName as c, type AIModelNameRuleFn as d, type AIModelNameRule as e, type RemoteFuncItem as f, SSEChannel as g, type SemaphoreIsReadyFuncType as h, type BinarySemaphoreAcquireOptions as i, type BinarySemaphoreReleaseOptions as j, type BinarySemaphoreReleaserFunc as k, type SemaphoreOptions as l, type SemaphoreTaskItem as m, BinarySemaphore as n, Semaphore as o, RateLimit as p, ToolAsyncCancelableBit as q, ToolAsyncPriorityBit as r, AsyncFeatureBits as s, AsyncFeatures as t, TaskAbortController as u, type TaskAbortControllers as v, type TaskPromise as w, CancelableAbility as x, makeToolFuncCancelable as y, type FuncParam as z };
|