@isdk/ai-tool 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/dist/chunk-COXUI4Q3.mjs +1 -0
  2. package/dist/funcs.js +1 -1
  3. package/dist/funcs.mjs +1 -1
  4. package/dist/index.d.mts +112 -5
  5. package/dist/index.d.ts +112 -5
  6. package/dist/index.js +1 -1
  7. package/dist/index.mjs +1 -1
  8. package/dist/test/util.mjs +1 -1
  9. package/docs/classes/AbortError.md +8 -8
  10. package/docs/classes/AlreadyExistsError.md +8 -8
  11. package/docs/classes/BaseError.md +8 -8
  12. package/docs/classes/CancelableAbility.md +20 -20
  13. package/docs/classes/ClientTools.md +74 -74
  14. package/docs/classes/CommonError.md +8 -8
  15. package/docs/classes/ConfigFile.md +19 -19
  16. package/docs/classes/EventClient.md +96 -96
  17. package/docs/classes/EventServer.md +97 -97
  18. package/docs/classes/EventToolFunc.md +65 -65
  19. package/docs/classes/FStringPromptTemplate.md +47 -47
  20. package/docs/classes/FewShotPromptTemplate.md +51 -51
  21. package/docs/classes/GolangPromptTemplate.md +47 -47
  22. package/docs/classes/HFEnvironment.md +9 -9
  23. package/docs/classes/HFInterpreter.md +19 -19
  24. package/docs/classes/HFTemplate.md +4 -4
  25. package/docs/classes/HfPromptTemplate.md +47 -47
  26. package/docs/classes/IntSet.md +12 -12
  27. package/docs/classes/NotFoundError.md +8 -8
  28. package/docs/classes/NotImplementationError.md +8 -8
  29. package/docs/classes/PromptExampleSelector.md +8 -8
  30. package/docs/classes/PromptTemplate.md +46 -46
  31. package/docs/classes/ReadableStreamError.md +8 -8
  32. package/docs/classes/ResClientTools.md +80 -80
  33. package/docs/classes/ResServerTools.md +81 -81
  34. package/docs/classes/SSEChannel.md +15 -15
  35. package/docs/classes/Semaphore.md +14 -14
  36. package/docs/classes/ServerTools.md +70 -70
  37. package/docs/classes/TaskAbortController.md +7 -7
  38. package/docs/classes/ToolFunc.md +62 -62
  39. package/docs/enums/AsyncFeatureBits.md +3 -3
  40. package/docs/enums/AsyncFeatures.md +3 -3
  41. package/docs/enums/ErrorCode.md +21 -21
  42. package/docs/enums/XXHashAlgorithm.md +2 -2
  43. package/docs/interfaces/AIChatAssistantMessageParam.md +6 -6
  44. package/docs/interfaces/AIChatContentPartImage.md +2 -2
  45. package/docs/interfaces/AIChatContentPartText.md +2 -2
  46. package/docs/interfaces/AIChatMessageParamBase.md +1 -1
  47. package/docs/interfaces/AIChatMessageToolCall.md +3 -3
  48. package/docs/interfaces/AIChatSystemMessageParam.md +3 -3
  49. package/docs/interfaces/AIChatToolMessageParam.md +4 -4
  50. package/docs/interfaces/AIChatUserMessageParam.md +7 -7
  51. package/docs/interfaces/AIChoiceConfig.md +85 -0
  52. package/docs/interfaces/AIResult.md +5 -5
  53. package/docs/interfaces/AIStreamParser.md +1 -1
  54. package/docs/interfaces/AIStreamParserOptions.md +1 -1
  55. package/docs/interfaces/BaseFunc.md +9 -9
  56. package/docs/interfaces/BaseFuncItem.md +8 -8
  57. package/docs/interfaces/CancelableAbilityOptions.md +8 -8
  58. package/docs/interfaces/ClientFuncItem.md +11 -11
  59. package/docs/interfaces/DotenvExpandOptions.md +3 -3
  60. package/docs/interfaces/DotenvExpandOutput.md +2 -2
  61. package/docs/interfaces/EventClientFuncParams.md +4 -4
  62. package/docs/interfaces/EventServerFuncParams.md +5 -5
  63. package/docs/interfaces/FewShotPromptTemplateOptions.md +11 -11
  64. package/docs/interfaces/FuncItem.md +9 -9
  65. package/docs/interfaces/FuncParam.md +6 -6
  66. package/docs/interfaces/ParseObjectArgumentOptions.md +63 -0
  67. package/docs/interfaces/PromptExampleSelectorOptions.md +2 -2
  68. package/docs/interfaces/PromptTemplateOptions.md +6 -6
  69. package/docs/interfaces/RemoteFuncItem.md +11 -11
  70. package/docs/interfaces/ResClientFuncParams.md +2 -2
  71. package/docs/interfaces/ResServerFuncParams.md +5 -5
  72. package/docs/interfaces/SanitizeFilenameOptions.md +2 -2
  73. package/docs/interfaces/ServerFuncItem.md +12 -12
  74. package/docs/interfaces/ServerFuncParams.md +2 -2
  75. package/docs/interfaces/StreamCallbacksAndOptions.md +4 -4
  76. package/docs/interfaces/TaskPromise.md +1 -1
  77. package/docs/interfaces/ToolFuncPackage.md +3 -3
  78. package/docs/modules.md +468 -151
  79. package/package.json +14 -10
  80. package/dist/chunk-U5DDQYSF.mjs +0 -1
  81. package/dist/chunk-W4ZFS46G.mjs +0 -1
  82. package/docs/interfaces/IOptions.md +0 -30
package/dist/index.d.ts CHANGED
@@ -6,8 +6,9 @@ export { e as AIModelNameRule, d as AIModelNameRuleFn, n as AbortError, j as Abo
6
6
  import { BaseFactory } from 'custom-factory';
7
7
  import { Event } from 'events-ex';
8
8
  import * as _base32768 from 'base32768';
9
+ import _memoize, { Options } from 'memoizee';
9
10
  export { NIL as uuidNIL, parse as uuidParse, stringify as uuidStringify, validate as uuidValidate, version as uuidVersion, v1 as uuidv1, v4 as uuidv4, v5 as uuidv5 } from 'uuid';
10
- export * from 'json-canonicalize';
11
+ export { canonicalize } from 'json-canonicalize';
11
12
  export { stringify as stringifyYaml } from 'yaml';
12
13
  export { mimeType } from 'mime-type/with-db';
13
14
  export { Config as ConfigFile } from 'load-config-file';
@@ -1254,6 +1255,7 @@ declare function getAllEnumKeys<T extends object>(enumType: T): Array<keyof type
1254
1255
  * console.log(json); // { name: 'John' }
1255
1256
  */
1256
1257
  declare function parseJsJson(input: string, scope?: Record<string, any>): any;
1258
+ declare function filterValidFnScope(scope?: Record<string, any>): Record<string, any> | undefined;
1257
1259
 
1258
1260
  /**
1259
1261
  * Retrieves an array of all key paths as strings for a nested object or array.
@@ -1270,6 +1272,19 @@ declare function getKeysPath<TValue extends object>(value: TValue): string[];
1270
1272
 
1271
1273
  declare function createEndWithRepetitionDetector(repetitionThreshold: number): (value: string) => RegExpExecArray | null;
1272
1274
 
1275
+ /**
1276
+ * Checks if a file (not a directory) exists at the specified path.
1277
+ *
1278
+ * @param filepath - The path to the file to check.
1279
+ * @returns true if the file exists and is not a directory; otherwise, false.
1280
+ *
1281
+ * @example
1282
+ * ```typescript
1283
+ * const exists = fileIsExists('path/to/file.txt');
1284
+ * console.log(exists); // Outputs: true or false
1285
+ * ```
1286
+ */
1287
+ declare function fileIsExists(filepath: string): boolean | undefined;
1273
1288
  /**
1274
1289
  * Loads a file from given paths, optionally searching for specific extensions.
1275
1290
  *
@@ -1301,16 +1316,21 @@ declare function loadTextFromPaths(filename: string, searchPaths?: string[], ext
1301
1316
  * Optionally filters the results using a file matching callback.
1302
1317
  *
1303
1318
  * @param dir - A single directory path or an array of directory paths to start the search from.
1304
- * @param isFileMatched - An optional callback that determines whether a file should be included in the result.
1319
+ * @param options.isFileMatched - An optional callback that determines whether a file should be included in the result.
1320
+ * @param options.signal - An optional signal to abort the operation.
1305
1321
  * @returns An array of file paths that match the criteria.
1306
1322
  *
1307
1323
  * @example
1308
1324
  * ```typescript
1309
- * const files = readFilenamesRecursiveSync('/path/to/directory', (filepath) => filepath.endsWith('.js'));
1325
+ * const files = readFilenamesRecursiveSync('/path/to/directory', {isFileMatched: (filepath) => filepath.endsWith('.js')});
1310
1326
  * console.log(files); // Outputs an array of JavaScript file paths.
1311
1327
  * ```
1312
1328
  */
1313
- declare function readFilenamesRecursiveSync(dir: string | string[], isFileMatched?: (filepath: string) => boolean, signal?: AbortSignal): string[];
1329
+ declare function readFilenamesRecursiveSync(dir: string | string[], options?: {
1330
+ isFileMatched?: (filepath: string) => boolean;
1331
+ signal?: AbortSignal;
1332
+ level?: number;
1333
+ }): string[];
1314
1334
  /**
1315
1335
  * Resolves the real file path, handling symbolic links.
1316
1336
  *
@@ -1464,4 +1484,91 @@ declare class IntSet {
1464
1484
  */
1465
1485
  declare function countRegexMatches(content: string, regex: RegExp): number;
1466
1486
 
1467
- export { type AIChatAssistantMessageParam, type AIChatContentPart, type AIChatContentPartImage, type AIChatContentPartText, type AIChatMessageParam, type AIChatMessageParamBase, type AIChatMessageToolCall, type AIChatRole, AIChatRoles, type AIChatSystemMessageParam, type AIChatToolMessageParam, type AIChatUserMessageParam, type AIMessageType, AIMessageTypes, AIModelNameRules, type AIResult, AIStream, type AIStreamParser, type AIStreamParserOptions, type AITextGenerationFinishReason, AITextGenerationFinishReasons, AsyncFeatures, type AsyncTaskId, BaseError, CancelableAbility, type CancelableAbilityOptions, CommonError, DefaultAsyncSemaphoreCapacity, type DotenvExpandOptions, type DotenvExpandOutput, type DotenvParseInput, type DotenvParseOutput, type DotenvPopulateInput, 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, HfPromptTemplate, IntSet, type JsonFilter, PromptExampleSelector, type PromptExampleSelectorOptions, type PromptExamples, PromptTemplate, type PromptTemplateOptions, type PromptTemplateType, PromptTemplateTypes, type PromptType, PromptTypes, RStreamErrCode, RateLimit, ReadableStreamError, ResponseRStreamErrCode, type SanitizeFilenameOptions, Semaphore, type StreamCallbacksAndOptions, TaskAbortController, type TaskAbortControllers, type TaskPromise, ToolFunc, WindowsReservedNameRegex, XXHashAlgorithm, backendEventable, base32768, countRegexMatches, createCallbacksTransformer, createEmptyReadableStream, createEndWithRepetitionDetector, createEventStreamTransformer, createHfValueFunc, dateToText, defaultTemplateFormat, expandEnv, expandObjEnv, extNameLevel, filenameReservedRegex, getAllEnumKeys, getConfigFileNames, getConfigs, getKeysPath, getMultiLevelExtname, getRealFilepath, getResponseErrorReadableStream, parse as hfParse, tokenize as hfTokenize, interpolateEnv, interpolateFString, interpolateGolangTemplate, isModelNameMatched, isValidFilename, isValidFilepath, isWebStream, jsonFilterToWhere, jsonToMarkdownStr, loadFileFromPaths, loadTextFromPaths, makeToolFuncCancelable, matchUrlProtocol, messagesToText, paramsSizeToScaleStr, parseFString, parseJsJson, parseYaml, reControlCharsRegex, readFilenamesRecursiveSync, readableFromAsyncIterable, registerYamlTag, sanitizeFilename, sanitizeFilepath, saveConfigFile, scaleStrToParamsSize, sortedValues, splitSentence, textToDate, toDateTime, trimStartOfStreamHelper, truncTo, uuid, wait, xxhash, xxhash32, xxhash64, xxhashAsStr };
1487
+ type ArgInfo = [boolean, string];
1488
+ type ArgProcessor = (arg: ArgInfo, ix: number, scope?: Record<string, any>, options?: ParseObjectArgumentOptions) => string | void | Promise<string | void>;
1489
+ interface AIChoiceConfig {
1490
+ items?: string[];
1491
+ maxPick?: number;
1492
+ minPick?: number;
1493
+ separator?: string;
1494
+ prefix?: string;
1495
+ type?: 'random' | 'ai';
1496
+ end?: string;
1497
+ }
1498
+ interface ParseObjectArgumentOptions {
1499
+ delimiter?: string;
1500
+ argProcessor?: ArgProcessor;
1501
+ returnArrayOnly?: boolean;
1502
+ templateFormat?: string;
1503
+ templateData?: Record<string, any>;
1504
+ }
1505
+ /**
1506
+ * Asynchronously parses a string of object arguments into an actual object.
1507
+ * @param argsStr The string of arguments to be parsed.
1508
+ * @param scope An optional scope object that provides values for variables during parsing.
1509
+ * @param options An optional configuration object containing the delimiter and argument processor.
1510
+ * @returns The parsed object or undefined.
1511
+ *
1512
+ * This function first parses the argument string into an object string and then converts it
1513
+ * into a proper JavaScript/JSON object based on the parsing results and configuration options.
1514
+ * It handles the conversion of single objects, arrays, and key-value pairs. The default delimiter
1515
+ * between parameters is a comma (`,`), but this can be customized using the `options.delimiter`.
1516
+ * Parameter assignment always uses an equal sign (`=`) and cannot be modified.
1517
+ *
1518
+ * The function returns:
1519
+ * - An object if the input string represents a set of key-value pairs.
1520
+ * - An array if the input string represents a sequence of elements, where each element can be
1521
+ * parsed as a number (indices are used as keys).
1522
+ * - A single value if the input string represents a single value or a single key-value pair.
1523
+ * - `undefined` if the input string is empty or cannot be parsed into a valid object.
1524
+ *
1525
+ * @example
1526
+ * ```typescript
1527
+ * // Example call with default delimiter
1528
+ * const result = await parseObjectArguments("name=John,age=30");
1529
+ * console.log(result); // Output: { name: 'John', age: '30' }
1530
+ *
1531
+ * // Example call with custom delimiter
1532
+ * const resultCustomDelimiter = await parseObjectArguments("name=John|age=30", undefined, { delimiter: '|' });
1533
+ * console.log(resultCustomDelimiter); // Output: { name: 'John', age: '30' }
1534
+ *
1535
+ * // Example with a single value
1536
+ * const singleValue = await parseObjectArguments("42");
1537
+ * console.log(singleValue); // Output: 42
1538
+ *
1539
+ * // Example with an array
1540
+ * const arrayResult = await parseObjectArguments("1,2,3");
1541
+ * console.log(arrayResult); // Output: [1, 2, 3]
1542
+ * ```
1543
+ */
1544
+ declare function parseObjectArguments(argsStr: string, scope?: Record<string, any>, options?: ParseObjectArgumentOptions): Promise<any>;
1545
+ declare function parseObjectArgumentInfos(args: ArgInfo[], scope?: Record<string, any>, options?: ParseObjectArgumentOptions): Promise<any>;
1546
+ declare function ChoiceArgProcessor(argInfo: ArgInfo, _ix: number, scope?: Record<string, any>, options?: ParseObjectArgumentOptions): string | undefined;
1547
+ declare function TemplateArgProcessor([isNamedArg, arg]: ArgInfo, ix: number, scope?: Record<string, any>, options?: ParseObjectArgumentOptions): Promise<string | undefined>;
1548
+ declare function AIArgProcessor(argInfo: ArgInfo, ix: number, scope?: Record<string, any>, options?: ParseObjectArgumentOptions): Promise<string | undefined>;
1549
+ declare function quoteStr(str: string): string;
1550
+ declare function parseObjectArgInfo(argInfo: ArgInfo, ix: number, scope?: Record<string, any>, options?: ParseObjectArgumentOptions): Promise<string>;
1551
+ /**
1552
+ * Parses an object arguments string into an array of ArgInfo.
1553
+ *
1554
+ * This function processes a parameter string and parses it according to specific rules, allowing for custom delimiters.
1555
+ * It can handle quotes, escape characters, and expressions within brackets. The parsing is designed to interpret
1556
+ * object literal strings from dynamic languages, such as JSON objects or similar custom formats.
1557
+ *
1558
+ * @param argsStr The string containing the arguments to be parsed.
1559
+ * @param scope An optional scope object used for further processing of the parsed arguments. Default is undefined.
1560
+ * @param options Parsing options, including:
1561
+ * - delimiter: The character used to separate arguments. Default is ','.
1562
+ * - argProcessor: An optional instance of ArgProcessor used for further processing of the parsed arguments.
1563
+ * @returns An array of parsed argument information, where each item contains a boolean indicating whether the argument is named,
1564
+ * and the string representation of the argument.
1565
+ */
1566
+ declare function parseObjectArgumentsAsArgInfos(argsStr: string, scope?: Record<string, any>, options?: ParseObjectArgumentOptions): ArgInfo[];
1567
+ declare function parseCommand(commandStr: string, scope?: Record<string, any>, options?: ParseObjectArgumentOptions): Promise<{
1568
+ command: string;
1569
+ args?: Record<string, any>;
1570
+ }>;
1571
+
1572
+ declare function memoize<F extends (...args: any[]) => any>(fn: any, options?: Options<F>): F & _memoize.Memoized<F>;
1573
+
1574
+ export { AIArgProcessor, type AIChatAssistantMessageParam, type AIChatContentPart, type AIChatContentPartImage, type AIChatContentPartText, type AIChatMessageParam, type AIChatMessageParamBase, type AIChatMessageToolCall, type AIChatRole, AIChatRoles, type AIChatSystemMessageParam, type AIChatToolMessageParam, type AIChatUserMessageParam, type AIChoiceConfig, type AIMessageType, AIMessageTypes, AIModelNameRules, type AIResult, AIStream, type AIStreamParser, type AIStreamParserOptions, type AITextGenerationFinishReason, AITextGenerationFinishReasons, AsyncFeatures, type AsyncTaskId, BaseError, CancelableAbility, type CancelableAbilityOptions, ChoiceArgProcessor, CommonError, DefaultAsyncSemaphoreCapacity, type DotenvExpandOptions, type DotenvExpandOutput, type DotenvParseInput, type DotenvParseOutput, type DotenvPopulateInput, 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, HfPromptTemplate, IntSet, type JsonFilter, type ParseObjectArgumentOptions, PromptExampleSelector, type PromptExampleSelectorOptions, type PromptExamples, PromptTemplate, type PromptTemplateOptions, type PromptTemplateType, PromptTemplateTypes, type PromptType, PromptTypes, RStreamErrCode, RateLimit, ReadableStreamError, ResponseRStreamErrCode, type SanitizeFilenameOptions, Semaphore, type StreamCallbacksAndOptions, TaskAbortController, type TaskAbortControllers, type TaskPromise, TemplateArgProcessor, ToolFunc, WindowsReservedNameRegex, XXHashAlgorithm, backendEventable, base32768, countRegexMatches, createCallbacksTransformer, createEmptyReadableStream, createEndWithRepetitionDetector, createEventStreamTransformer, createHfValueFunc, dateToText, defaultTemplateFormat, expandEnv, expandObjEnv, extNameLevel, fileIsExists, filenameReservedRegex, filterValidFnScope, getAllEnumKeys, getConfigFileNames, getConfigs, getKeysPath, getMultiLevelExtname, getRealFilepath, getResponseErrorReadableStream, parse as hfParse, tokenize as hfTokenize, interpolateEnv, interpolateFString, interpolateGolangTemplate, isModelNameMatched, isValidFilename, isValidFilepath, isWebStream, jsonFilterToWhere, jsonToMarkdownStr, loadFileFromPaths, loadTextFromPaths, makeToolFuncCancelable, matchUrlProtocol, memoize, messagesToText, paramsSizeToScaleStr, parseCommand, parseFString, parseJsJson, parseObjectArgInfo, parseObjectArgumentInfos, parseObjectArguments, parseObjectArgumentsAsArgInfos, parseYaml, quoteStr, reControlCharsRegex, readFilenamesRecursiveSync, readableFromAsyncIterable, registerYamlTag, sanitizeFilename, sanitizeFilepath, saveConfigFile, scaleStrToParamsSize, sortedValues, splitSentence, textToDate, toDateTime, trimStartOfStreamHelper, truncTo, uuid, wait, xxhash, xxhash32, xxhash64, xxhashAsStr };