@isdk/ai-tool 0.0.7 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.cn.md +49 -15
- package/README.md +245 -2
- package/dist/chunk-PDXMSKQH.mjs +1 -0
- package/dist/funcs.d.mts +1 -1
- package/dist/funcs.d.ts +1 -1
- package/dist/funcs.js +1 -1
- package/dist/funcs.mjs +1 -1
- package/dist/{index-japi6bEq.d.mts → index-Dgo3ZXPQ.d.mts} +28 -2
- package/dist/{index-japi6bEq.d.ts → index-Dgo3ZXPQ.d.ts} +28 -2
- package/dist/index.d.mts +369 -53
- package/dist/index.d.ts +369 -53
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/docs/README.md +245 -2
- package/docs/classes/AbortError.md +8 -8
- package/docs/classes/AlreadyExistsError.md +8 -8
- package/docs/classes/BaseError.md +8 -8
- package/docs/classes/CancelableAbility.md +431 -0
- package/docs/classes/ClientTools.md +101 -51
- package/docs/classes/CommonError.md +8 -8
- package/docs/classes/EventClient.md +123 -73
- package/docs/classes/EventServer.md +121 -71
- package/docs/classes/EventToolFunc.md +91 -41
- package/docs/classes/FStringPromptTemplate.md +18 -18
- package/docs/classes/FewShotPromptTemplate.md +22 -22
- package/docs/classes/GolangPromptTemplate.md +18 -18
- package/docs/classes/HFEnvironment.md +9 -9
- package/docs/classes/HFInterpreter.md +39 -17
- package/docs/classes/HFTemplate.md +4 -4
- package/docs/classes/HfPromptTemplate.md +18 -18
- package/docs/classes/IntSet.md +249 -0
- package/docs/classes/NotFoundError.md +8 -8
- package/docs/classes/NotImplementationError.md +8 -8
- package/docs/classes/PromptExampleSelector.md +8 -8
- package/docs/classes/PromptTemplate.md +17 -17
- package/docs/classes/ReadableStreamError.md +8 -8
- package/docs/classes/ResClientTools.md +107 -57
- package/docs/classes/ResServerTools.md +105 -55
- package/docs/classes/SSEChannel.md +15 -15
- package/docs/classes/Semaphore.md +273 -0
- package/docs/classes/ServerTools.md +98 -48
- package/docs/classes/TaskAbortController.md +157 -0
- package/docs/classes/ToolFunc.md +80 -38
- package/docs/enums/AsyncFeatureBits.md +41 -0
- package/docs/enums/AsyncFeatures.md +41 -0
- package/docs/enums/ErrorCode.md +41 -19
- package/docs/enums/XXHashAlgorithm.md +2 -2
- package/docs/interfaces/AIChatAssistantMessageParam.md +6 -6
- package/docs/interfaces/AIChatContentPartImage.md +2 -2
- package/docs/interfaces/AIChatContentPartText.md +2 -2
- package/docs/interfaces/AIChatMessageParamBase.md +1 -1
- package/docs/interfaces/AIChatMessageToolCall.md +3 -3
- package/docs/interfaces/AIChatSystemMessageParam.md +3 -3
- package/docs/interfaces/AIChatToolMessageParam.md +4 -4
- package/docs/interfaces/AIChatUserMessageParam.md +7 -7
- package/docs/interfaces/AIResult.md +16 -5
- package/docs/interfaces/AIStreamParser.md +1 -1
- package/docs/interfaces/AIStreamParserOptions.md +1 -1
- package/docs/interfaces/BaseFunc.md +7 -7
- package/docs/interfaces/BaseFuncItem.md +6 -6
- package/docs/interfaces/CancelableAbilityOptions.md +126 -0
- package/docs/interfaces/ClientFuncItem.md +10 -10
- package/docs/interfaces/DotenvExpandOptions.md +3 -3
- package/docs/interfaces/DotenvExpandOutput.md +2 -2
- package/docs/interfaces/EventClientFuncParams.md +4 -4
- package/docs/interfaces/EventServerFuncParams.md +5 -5
- package/docs/interfaces/FewShotPromptTemplateOptions.md +11 -11
- package/docs/interfaces/FuncItem.md +7 -7
- package/docs/interfaces/FuncParam.md +16 -5
- package/docs/interfaces/PromptExampleSelectorOptions.md +2 -2
- package/docs/interfaces/PromptTemplateOptions.md +6 -6
- package/docs/interfaces/RemoteFuncItem.md +10 -10
- package/docs/interfaces/ResClientFuncParams.md +2 -2
- package/docs/interfaces/ResServerFuncParams.md +5 -5
- package/docs/interfaces/SanitizeFilenameOptions.md +2 -2
- package/docs/interfaces/ServerFuncItem.md +11 -11
- package/docs/interfaces/ServerFuncParams.md +2 -2
- package/docs/interfaces/StreamCallbacksAndOptions.md +124 -0
- package/docs/interfaces/TaskAbortControllers.md +7 -0
- package/docs/interfaces/TaskPromise.md +151 -0
- package/docs/interfaces/ToolFuncPackage.md +63 -0
- package/docs/modules.md +1130 -123
- package/package.json +3 -2
- package/dist/chunk-PYM7DCYB.mjs +0 -1
- package/docs/interfaces/AIStreamCallbacksAndOptions.md +0 -158
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { B as BaseError, A as AIModelNameRules } from './index-japi6bEq.js';
|
|
2
|
-
export { d as AIModelNameRule, c as AIModelNameRuleFn, m as AbortError, i as AbortErrorCode, b as ActionName, a as ActionNames, l as AlreadyExistsError, h as AlreadyExistsErrorCode, u as BaseFunc, r as BaseFuncItem, y as ClientFuncItem, D as ClientToolFuncSchema, z as ClientTools, C as CommonError, f as ErrorCode, E as ErrorCodeType, W as EventClient, V as EventClientFuncParams, Z as EventServer, Y as EventServerFuncParams, M as EventToolFunc, s as FuncItem, p as FuncParam, F as FuncParamType, q as FuncParams, v as Funcs, I as InternalErrorCode, k as NotFoundError, g as NotFoundErrorCode, j as NotImplementationError, N as NotImplementedErrorCode, P as PASSING_SCORE, e as RemoteFuncItem, R as RemoteToolFuncSchema, a0 as ResClientFuncParams, a1 as ResClientTools, a2 as ResClientToolsSchema, a3 as ResServerFuncParams, a4 as ResServerTools, a5 as ResServerToolsSchema, o as SSEChannel, S as SSEChannelAlreadyClosedErrCode, H as ServerFuncItem, G as ServerFuncParams, K as ServerToolFuncSchema, J as ServerTools, T as TFunc, w as ToolFunc, x as ToolFuncSchema, _ as _lrucache, n as createError, Q as createLRUCache, O as event, X as eventClient, $ as eventServer, U as lrucache, L as registerCoreTools, t as throwError } from './index-japi6bEq.js';
|
|
3
|
-
import { BaseFactory } from 'custom-factory';
|
|
4
1
|
import * as custom_ability from 'custom-ability';
|
|
2
|
+
import { AbilityOptions } from 'custom-ability';
|
|
3
|
+
export { createAbilityInjector } from 'custom-ability';
|
|
4
|
+
import { A as AsyncFeatures, C as CommonError, T as ToolFunc, B as BaseError, a as AIModelNameRules } from './index-Dgo3ZXPQ.js';
|
|
5
|
+
export { e as AIModelNameRule, d as AIModelNameRuleFn, n as AbortError, j as AbortErrorCode, c as ActionName, b as ActionNames, m as AlreadyExistsError, i as AlreadyExistsErrorCode, u as AsyncFeatureBits, D as BaseFunc, y as BaseFuncItem, K as ClientFuncItem, M as ClientToolFuncSchema, L as ClientTools, g as ErrorCode, E as ErrorCodeType, a1 as EventClient, a0 as EventClientFuncParams, a4 as EventServer, a3 as EventServerFuncParams, X as EventToolFunc, z as FuncItem, v as FuncParam, F as FuncParamType, w as FuncParams, G as Funcs, I as InternalErrorCode, l as NotFoundError, h as NotFoundErrorCode, k as NotImplementationError, N as NotImplementedErrorCode, P as PASSING_SCORE, f as RemoteFuncItem, R as RemoteToolFuncSchema, a6 as ResClientFuncParams, a7 as ResClientTools, a8 as ResClientToolsSchema, a9 as ResServerFuncParams, aa as ResServerTools, ab as ResServerToolsSchema, p as SSEChannel, S as SSEChannelAlreadyClosedErrCode, Q as ServerFuncItem, O as ServerFuncParams, V as ServerToolFuncSchema, U as ServerTools, x as TFunc, r as ToolAsyncCancelableBit, q as ToolAsyncMultiTaskBit, s as ToolAsyncPriorityBit, H as ToolFuncPackage, J as ToolFuncSchema, _ as _lrucache, o as createError, Z as createLRUCache, Y as event, a2 as eventClient, a5 as eventServer, $ as lrucache, W as registerCoreTools, t as throwError } from './index-Dgo3ZXPQ.js';
|
|
6
|
+
import { BaseFactory } from 'custom-factory';
|
|
5
7
|
import { Event } from 'events-ex';
|
|
6
8
|
import * as _base32768 from 'base32768';
|
|
7
9
|
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';
|
|
@@ -9,11 +11,227 @@ export * from 'json-canonicalize';
|
|
|
9
11
|
export { stringify as stringifyYaml } from 'yaml';
|
|
10
12
|
export { mimeType } from 'mime-type/with-db';
|
|
11
13
|
export { Config as ConfigFile } from 'load-config-file';
|
|
14
|
+
export { formatISO, parse as parseDateFormat, parseISO, toDate } from 'date-fns';
|
|
12
15
|
import 'property-manager';
|
|
13
16
|
import 'secondary-cache';
|
|
14
17
|
import 'abstract-error';
|
|
15
18
|
import 'http';
|
|
16
19
|
|
|
20
|
+
declare const DefaultAsyncSemaphoreCapacity = 32;
|
|
21
|
+
declare class Deque {
|
|
22
|
+
private _capacity;
|
|
23
|
+
private _length;
|
|
24
|
+
private _front;
|
|
25
|
+
private arr;
|
|
26
|
+
constructor(capacity: number);
|
|
27
|
+
push(item: any): number;
|
|
28
|
+
pop(): any;
|
|
29
|
+
shift(): any;
|
|
30
|
+
get length(): number;
|
|
31
|
+
private checkCapacity;
|
|
32
|
+
private resizeTo;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* A Semaphore implementation for managing concurrency in asynchronous operations.
|
|
36
|
+
* Semaphores allow a fixed number of resources to be accessed concurrently.
|
|
37
|
+
*
|
|
38
|
+
* Example usage:
|
|
39
|
+
*
|
|
40
|
+
* ```typescript
|
|
41
|
+
* const semaphore = new Semaphore(5); // Allows 5 concurrent operations.
|
|
42
|
+
*
|
|
43
|
+
* const semaphore = new Semaphore(
|
|
44
|
+
* 4, // Allow 4 concurrent async calls
|
|
45
|
+
* {
|
|
46
|
+
* capacity: 100 // Prealloc space for 100 tokens
|
|
47
|
+
* }
|
|
48
|
+
* );
|
|
49
|
+
*
|
|
50
|
+
* async function fetchData(x) {
|
|
51
|
+
* await semaphore.acquire()
|
|
52
|
+
* try {
|
|
53
|
+
* console.log(semaphore.pendingCount() + ' calls to fetch are waiting')
|
|
54
|
+
* // ... do some async stuff with x
|
|
55
|
+
* } finally {
|
|
56
|
+
* semaphore.release();
|
|
57
|
+
* }
|
|
58
|
+
* }
|
|
59
|
+
*
|
|
60
|
+
* const data = await Promise.all(array.map(fetchData));
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
declare class Semaphore {
|
|
64
|
+
readonly maxConcurrency: number;
|
|
65
|
+
readonly waiting: Deque;
|
|
66
|
+
private free;
|
|
67
|
+
private releaseEmitter;
|
|
68
|
+
private useDefaultTokens;
|
|
69
|
+
private pauseFn?;
|
|
70
|
+
private resumeFn?;
|
|
71
|
+
private paused;
|
|
72
|
+
/**
|
|
73
|
+
* Creates a semaphore object. The first argument is the maximum concurrently number and the second argument is optional.
|
|
74
|
+
*
|
|
75
|
+
* @param maxConcurrency The maximum number of callers allowed to acquire the semaphore concurrently.
|
|
76
|
+
* @param options.initFn Function that is used to initialize the tokens used to manage the semaphore. The default is () => '1'.
|
|
77
|
+
* @param options.pauseFn An optional fuction that is called to opportunistically request pausing the the incoming stream of data,
|
|
78
|
+
* instead of piling up waiting promises and possibly running out of memory. See examples/pausing.js.
|
|
79
|
+
* @param options.resumeFn An optional function that is called when there is room again to accept new waiters on the semaphore.
|
|
80
|
+
* This function must be declared if a pauseFn is declared.
|
|
81
|
+
* @param options.capacity Sets the size of the preallocated waiting list inside the semaphore.
|
|
82
|
+
* This is typically used by high performance where the developer can make a rough estimate of the number of concurrent users of a semaphore.
|
|
83
|
+
*
|
|
84
|
+
* ```ts
|
|
85
|
+
* const readline = require('readline');
|
|
86
|
+
*
|
|
87
|
+
* const rl = readline.createInterface({
|
|
88
|
+
* input: process.stdin,
|
|
89
|
+
* output: process.stdout,
|
|
90
|
+
* terminal: false
|
|
91
|
+
* });
|
|
92
|
+
*
|
|
93
|
+
* function pause() {
|
|
94
|
+
* console.log('Pausing the stream');
|
|
95
|
+
* rl.pause();
|
|
96
|
+
* }
|
|
97
|
+
*
|
|
98
|
+
* function resume() {
|
|
99
|
+
* console.log('Resuming the stream');
|
|
100
|
+
* rl.resume();
|
|
101
|
+
* }
|
|
102
|
+
*
|
|
103
|
+
* const s = new Semaphore(5, { pauseFn: pause, resumeFn: resume });
|
|
104
|
+
*
|
|
105
|
+
* async function parse(line) {
|
|
106
|
+
* await s.acquire();
|
|
107
|
+
*
|
|
108
|
+
* console.log(line);
|
|
109
|
+
*
|
|
110
|
+
* s.release();
|
|
111
|
+
* }
|
|
112
|
+
*
|
|
113
|
+
* rl.on('line', line => {
|
|
114
|
+
* parse(line).catch(console.error);
|
|
115
|
+
* });
|
|
116
|
+
* ```
|
|
117
|
+
*
|
|
118
|
+
*/
|
|
119
|
+
constructor(maxConcurrency: number, { initFn, pauseFn, resumeFn, capacity, }?: {
|
|
120
|
+
initFn?: () => any;
|
|
121
|
+
pauseFn?: () => void;
|
|
122
|
+
resumeFn?: () => void;
|
|
123
|
+
capacity?: number;
|
|
124
|
+
});
|
|
125
|
+
/**
|
|
126
|
+
* Attempt to acquire a token from the semaphore, if one is available immediately. Otherwise, return undefined.
|
|
127
|
+
*/
|
|
128
|
+
tryAcquire(): any | undefined;
|
|
129
|
+
/**
|
|
130
|
+
* 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.
|
|
131
|
+
*/
|
|
132
|
+
acquire(signal?: AbortSignal): Promise<any>;
|
|
133
|
+
/**
|
|
134
|
+
* 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.
|
|
135
|
+
*/
|
|
136
|
+
release(token?: any): void;
|
|
137
|
+
/**
|
|
138
|
+
* 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.
|
|
139
|
+
*/
|
|
140
|
+
drain(): Promise<any[]>;
|
|
141
|
+
/**
|
|
142
|
+
* Returns the number of callers waiting on the semaphore, i.e. the number of pending promises.
|
|
143
|
+
*
|
|
144
|
+
* @returns The number of waiters in the waiting list.
|
|
145
|
+
*/
|
|
146
|
+
pendingCount(): number;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* 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.
|
|
150
|
+
*
|
|
151
|
+
* @param rps
|
|
152
|
+
* @param options.timeUnit The `timeUnit` is an optional argument setting the width of the rate limiting window in milliseconds.
|
|
153
|
+
* The default `timeUnit` is 1000 ms, therefore making the rps argument act as requests per second limit.
|
|
154
|
+
* @param options.uniformDistribution The `uniformDistribution` argument enforces a discrete uniform distribution over time,
|
|
155
|
+
* instead of the default that allows hitting the function rps time and then pausing for timeWindow milliseconds. Setting
|
|
156
|
+
* the `uniformDistribution` option is mainly useful in a situation where the flow of rate limit function calls is continuous
|
|
157
|
+
* and and occuring faster than timeUnit (e.g. reading a file) and not enabling it would cause the maximum number of calls to
|
|
158
|
+
* resolve immediately (thus exhaust the limit immediately) and therefore the next bunch calls would need to wait for timeWindow
|
|
159
|
+
* milliseconds. However if the flow is sparse then this option may make the code run slower with no advantages.
|
|
160
|
+
*
|
|
161
|
+
* Examples:
|
|
162
|
+
*
|
|
163
|
+
* ```ts
|
|
164
|
+
* async function f() {
|
|
165
|
+
* const lim = RateLimit(5); // rps
|
|
166
|
+
*
|
|
167
|
+
* for (let i = 0; i < n; i++) {
|
|
168
|
+
* await lim();
|
|
169
|
+
* // ... do something async
|
|
170
|
+
* }
|
|
171
|
+
* }
|
|
172
|
+
* ```
|
|
173
|
+
*
|
|
174
|
+
*
|
|
175
|
+
*/
|
|
176
|
+
declare function RateLimit(rps: number, { timeUnit, uniformDistribution, }?: {
|
|
177
|
+
timeUnit?: number;
|
|
178
|
+
uniformDistribution?: boolean;
|
|
179
|
+
}): () => Promise<void>;
|
|
180
|
+
|
|
181
|
+
type AsyncTaskId = string | number;
|
|
182
|
+
interface CancelableAbilityOptions extends AbilityOptions {
|
|
183
|
+
asyncFeatures?: AsyncFeatures;
|
|
184
|
+
maxTaskConcurrency?: number;
|
|
185
|
+
}
|
|
186
|
+
declare class TaskAbortController extends AbortController {
|
|
187
|
+
id?: AsyncTaskId;
|
|
188
|
+
timeoutId?: any;
|
|
189
|
+
streamController?: ReadableStreamDefaultController;
|
|
190
|
+
parent: CancelableAbility;
|
|
191
|
+
constructor(parent: CancelableAbility);
|
|
192
|
+
abort(reason?: string | Error | CommonError, data?: any): void;
|
|
193
|
+
throwRejected(alreadyRejected?: boolean): true | undefined;
|
|
194
|
+
}
|
|
195
|
+
interface TaskAbortControllers {
|
|
196
|
+
[k: AsyncTaskId]: TaskAbortController | undefined;
|
|
197
|
+
}
|
|
198
|
+
interface TaskPromise<T = any> extends Promise<T> {
|
|
199
|
+
task?: TaskAbortController;
|
|
200
|
+
}
|
|
201
|
+
declare interface CancelableAbility {
|
|
202
|
+
_asyncFeatures?: number;
|
|
203
|
+
_maxTaskConcurrency: number | undefined;
|
|
204
|
+
[name: string]: any;
|
|
205
|
+
}
|
|
206
|
+
declare class CancelableAbility {
|
|
207
|
+
generateAsyncTaskId: (taskId?: AsyncTaskId, aborters?: TaskAbortControllers) => AsyncTaskId;
|
|
208
|
+
cleanMultiTaskAborter: (id: AsyncTaskId, aborters: TaskAbortControllers) => void;
|
|
209
|
+
__task_aborter: TaskAbortController | TaskAbortControllers | undefined;
|
|
210
|
+
__task_semaphore: Semaphore | undefined;
|
|
211
|
+
get maxTaskConcurrency(): number | undefined;
|
|
212
|
+
get semaphore(): Semaphore | undefined;
|
|
213
|
+
isAborted(taskId?: AsyncTaskId): boolean;
|
|
214
|
+
getRunningTask(taskId?: AsyncTaskId): TaskAbortController | undefined;
|
|
215
|
+
getRunningTaskCount(): number;
|
|
216
|
+
_generateAsyncTaskId(taskId?: AsyncTaskId, aborters?: TaskAbortControllers): AsyncTaskId;
|
|
217
|
+
$generateAsyncTaskId(taskId?: AsyncTaskId, aborters?: TaskAbortControllers): AsyncTaskId | undefined;
|
|
218
|
+
createAborter(params?: any, taskId?: AsyncTaskId, raiseError?: boolean): TaskAbortController;
|
|
219
|
+
$cleanMultiTaskAborter(id: AsyncTaskId, aborters: TaskAbortControllers): void;
|
|
220
|
+
cleanTaskAborter(aborter: TaskAbortController): void;
|
|
221
|
+
_cleanMultiTaskAborter(id: AsyncTaskId, aborters: TaskAbortControllers): void;
|
|
222
|
+
createTaskPromise<Output = any>(runTask: (params: Record<string, any>, aborter: TaskAbortController) => Promise<Output>, params: Record<string, any>, options?: {
|
|
223
|
+
taskId?: AsyncTaskId;
|
|
224
|
+
raiseError?: boolean;
|
|
225
|
+
}): TaskPromise<Output>;
|
|
226
|
+
runAsyncCancelableTask<Output = any>(params: Record<string, any> | undefined, runTask: (params: Record<string, any>, aborter: TaskAbortController) => Promise<Output>, options?: {
|
|
227
|
+
taskId?: AsyncTaskId;
|
|
228
|
+
raiseError?: boolean;
|
|
229
|
+
}): TaskPromise<Output>;
|
|
230
|
+
abort(reason?: string, data?: any): void;
|
|
231
|
+
}
|
|
232
|
+
type ToolFuncCancelableFn = (Tool: typeof ToolFunc, options?: CancelableAbilityOptions) => typeof ToolFunc;
|
|
233
|
+
declare const makeToolFuncCancelable: ToolFuncCancelableFn;
|
|
234
|
+
|
|
17
235
|
declare const AITextGenerationFinishReasons: readonly ["stop", "length", "content-filter", "tool-calls", "abort", "error", "other", null];
|
|
18
236
|
type AITextGenerationFinishReason = typeof AITextGenerationFinishReasons[number];
|
|
19
237
|
interface AIResult<TValue = any, TOptions = any> {
|
|
@@ -30,6 +248,7 @@ interface AIResult<TValue = any, TOptions = any> {
|
|
|
30
248
|
* for stream mode
|
|
31
249
|
*/
|
|
32
250
|
stop?: boolean;
|
|
251
|
+
taskId?: AsyncTaskId;
|
|
33
252
|
}
|
|
34
253
|
declare const AIMessageTypes: readonly ["human", "ai", "generic", "system", "tool"];
|
|
35
254
|
type AIMessageType = typeof AIMessageTypes[number];
|
|
@@ -87,6 +306,7 @@ interface AIChatToolMessageParam extends AIChatMessageParamBase {
|
|
|
87
306
|
tool_call_id: string;
|
|
88
307
|
templateFormat?: string;
|
|
89
308
|
}
|
|
309
|
+
declare function messagesToText(messages: AIChatMessageParamBase[]): string;
|
|
90
310
|
|
|
91
311
|
/**
|
|
92
312
|
* Prompt Type
|
|
@@ -469,6 +689,7 @@ declare class Interpreter {
|
|
|
469
689
|
private evalProgram;
|
|
470
690
|
private evaluateBlock;
|
|
471
691
|
private evaluateIdentifier;
|
|
692
|
+
private evaluateArgumentsExpression;
|
|
472
693
|
private evaluateCallExpression;
|
|
473
694
|
private evaluateSliceExpression;
|
|
474
695
|
private evaluateMemberExpression;
|
|
@@ -506,9 +727,13 @@ declare function randomInt(to: number, from?: number): number;
|
|
|
506
727
|
* console.log(select(str, -1)) // Last character
|
|
507
728
|
*/
|
|
508
729
|
declare function select(obj: any | any[], index?: number | string): any;
|
|
730
|
+
declare function tojson(value: any, indent?: string | number | {
|
|
731
|
+
indent?: string | number;
|
|
732
|
+
}): string;
|
|
509
733
|
declare const builtins: {
|
|
510
734
|
randomInt: typeof randomInt;
|
|
511
735
|
select: typeof select;
|
|
736
|
+
tojson: typeof tojson;
|
|
512
737
|
};
|
|
513
738
|
|
|
514
739
|
/**
|
|
@@ -764,6 +989,8 @@ type EventListenerFn = (this: Event, name: string, ...args: any) => any;
|
|
|
764
989
|
type EventErrorListenerFn = (this: Event, err: Error, name: string, ...args: any) => any;
|
|
765
990
|
declare const backendEventable: custom_ability.AbilityFn;
|
|
766
991
|
|
|
992
|
+
declare function isWebStream(val: any): boolean;
|
|
993
|
+
|
|
767
994
|
declare const RStreamErrCode = 600;
|
|
768
995
|
declare const ResponseRStreamErrCode = 601;
|
|
769
996
|
declare class ReadableStreamError extends BaseError {
|
|
@@ -780,29 +1007,6 @@ declare function getResponseErrorReadableStream(body?: ReadableStream<Uint8Array
|
|
|
780
1007
|
*/
|
|
781
1008
|
declare function createEmptyReadableStream(): ReadableStream;
|
|
782
1009
|
|
|
783
|
-
/**
|
|
784
|
-
* Configuration options and helper callback methods for AIStream stream lifecycle events.
|
|
785
|
-
* @interface
|
|
786
|
-
*/
|
|
787
|
-
interface AIStreamCallbacksAndOptions {
|
|
788
|
-
/** `onStart`: Called once when the stream is initialized. */
|
|
789
|
-
onStart?: () => Promise<void> | void;
|
|
790
|
-
/** `onCompletion`: Called for each tokenized message. */
|
|
791
|
-
onCompletion?: (completion: string) => Promise<void> | void;
|
|
792
|
-
/** `onFinal`: Called once when the stream is closed with the final completion message. */
|
|
793
|
-
onFinal?: (completion: string) => Promise<void> | void;
|
|
794
|
-
/** `onToken`: Called for each tokenized message. */
|
|
795
|
-
onToken?: (token: string) => Promise<void> | void;
|
|
796
|
-
/** `onText`: Called for each text chunk. */
|
|
797
|
-
onText?: (text: string) => Promise<void> | void;
|
|
798
|
-
/**
|
|
799
|
-
* A flag for enabling the experimental_StreamData class and the new protocol.
|
|
800
|
-
* @see https://github.com/vercel-labs/ai/pull/425
|
|
801
|
-
*
|
|
802
|
-
* When StreamData is rolled out, this will be removed and the new protocol will be used by default.
|
|
803
|
-
*/
|
|
804
|
-
experimental_streamData?: boolean;
|
|
805
|
-
}
|
|
806
1010
|
/**
|
|
807
1011
|
* Options for the AIStreamParser.
|
|
808
1012
|
* @interface
|
|
@@ -827,29 +1031,6 @@ interface AIStreamParser<T = any, TOptions = any> {
|
|
|
827
1031
|
* @returns TransformStream parsing events.
|
|
828
1032
|
*/
|
|
829
1033
|
declare function createEventStreamTransformer<TValue = any, TOptions = any>(customParser?: AIStreamParser): TransformStream<Uint8Array, AIResult<TValue, TOptions>>;
|
|
830
|
-
/**
|
|
831
|
-
* Creates a transform stream that encodes input messages and invokes optional callback functions.
|
|
832
|
-
* The transform stream uses the provided callbacks to execute custom logic at different stages of the stream's lifecycle.
|
|
833
|
-
* - `onStart`: Called once when the stream is initialized.
|
|
834
|
-
* - `onToken`: Called for each tokenized message.
|
|
835
|
-
* - `onCompletion`: Called every time an AIStream completion message is received. This can occur multiple times when using e.g. OpenAI functions
|
|
836
|
-
* - `onFinal`: Called once when the stream is closed with the final completion message.
|
|
837
|
-
*
|
|
838
|
-
* This function is useful when you want to process a stream of messages and perform specific actions during the stream's lifecycle.
|
|
839
|
-
*
|
|
840
|
-
* @param {AIStreamCallbacksAndOptions} [callbacks] - An object containing the callback functions.
|
|
841
|
-
* @return {TransformStream<string, Uint8Array>} A transform stream that encodes input messages as Uint8Array and allows the execution of custom logic through callbacks.
|
|
842
|
-
*
|
|
843
|
-
* @example
|
|
844
|
-
* const callbacks = {
|
|
845
|
-
* onStart: async () => console.log('Stream started'),
|
|
846
|
-
* onToken: async (token) => console.log(`Token: ${token}`),
|
|
847
|
-
* onCompletion: async (completion) => console.log(`Completion: ${completion}`)
|
|
848
|
-
* onFinal: async () => data.close()
|
|
849
|
-
* };
|
|
850
|
-
* const transformer = createCallbacksTransformer(callbacks);
|
|
851
|
-
*/
|
|
852
|
-
declare function createCallbacksTransformer(cb: AIStreamCallbacksAndOptions | undefined): TransformStream<AIResult, Uint8Array>;
|
|
853
1034
|
/**
|
|
854
1035
|
* Returns a stateful function that, when invoked, trims leading whitespace
|
|
855
1036
|
* from the input text. The trimming only occurs on the first invocation, ensuring that
|
|
@@ -891,6 +1072,42 @@ declare function AIStream<T = any, TOptions = any>(response: Response, customPar
|
|
|
891
1072
|
*/
|
|
892
1073
|
declare function readableFromAsyncIterable<T>(iterable: AsyncIterable<T>): ReadableStream<T>;
|
|
893
1074
|
|
|
1075
|
+
/**
|
|
1076
|
+
* Configuration options and helper callback methods for stream lifecycle events.
|
|
1077
|
+
* @interface
|
|
1078
|
+
*/
|
|
1079
|
+
interface StreamCallbacksAndOptions<I = any, O = any> {
|
|
1080
|
+
/** `onStart`: Called once when the stream is initialized. */
|
|
1081
|
+
onStart?: (controller: TransformStreamDefaultController) => Promise<void> | void;
|
|
1082
|
+
/** `onToken`: Called for each tokenized message. */
|
|
1083
|
+
onTransform?: (chunk: I, controller: TransformStreamDefaultController) => Promise<O | void> | O | void;
|
|
1084
|
+
/** `onFinal`: Called once when the stream is closed with the final completion message. */
|
|
1085
|
+
onFinal?: (controller: TransformStreamDefaultController) => Promise<void> | void;
|
|
1086
|
+
onError?: (error: Error) => Promise<void> | void;
|
|
1087
|
+
}
|
|
1088
|
+
/**
|
|
1089
|
+
* Creates a transform stream that invokes optional callback functions.
|
|
1090
|
+
* The transform stream uses the provided callbacks to execute custom logic at different stages of the stream's lifecycle.
|
|
1091
|
+
* - `onStart`: Called once when the stream is initialized.
|
|
1092
|
+
* - `onTransform`: Called for each tokenized message.
|
|
1093
|
+
* - `onCompletion`: Called every time an AIStream completion message is received. This can occur multiple times when using e.g. OpenAI functions
|
|
1094
|
+
* - `onFinal`: Called once when the stream is closed with the final completion message.
|
|
1095
|
+
*
|
|
1096
|
+
* This function is useful when you want to process a stream of messages and perform specific actions during the stream's lifecycle.
|
|
1097
|
+
*
|
|
1098
|
+
* @param [callbacks] - An object containing the callback functions.
|
|
1099
|
+
* @return A transform stream that encodes input messages as Uint8Array and allows the execution of custom logic through callbacks.
|
|
1100
|
+
*
|
|
1101
|
+
* @example
|
|
1102
|
+
* const callbacks = {
|
|
1103
|
+
* onStart: async () => console.log('Stream started'),
|
|
1104
|
+
* onTransform: async (chunk) => console.log('Token:',chunk),
|
|
1105
|
+
* onFinal: async () => data.close()
|
|
1106
|
+
* };
|
|
1107
|
+
* const transformer = createCallbacksTransformer(callbacks);
|
|
1108
|
+
*/
|
|
1109
|
+
declare function createCallbacksTransformer<I = any, O = any>(cb: StreamCallbacksAndOptions<I, O> | undefined): TransformStream<I, O>;
|
|
1110
|
+
|
|
894
1111
|
declare function uuid(ver?: 1 | 4 | 5, encode?: boolean): string;
|
|
895
1112
|
|
|
896
1113
|
declare const base32768: typeof _base32768;
|
|
@@ -1044,7 +1261,7 @@ declare function parseJsJson(input: string, scope?: Record<string, any>): any;
|
|
|
1044
1261
|
*/
|
|
1045
1262
|
declare function getKeysPath<TValue extends object>(value: TValue): string[];
|
|
1046
1263
|
|
|
1047
|
-
declare function createEndWithRepetitionDetector(repetitionThreshold: number): (value: string) =>
|
|
1264
|
+
declare function createEndWithRepetitionDetector(repetitionThreshold: number): (value: string) => RegExpExecArray | null;
|
|
1048
1265
|
|
|
1049
1266
|
/**
|
|
1050
1267
|
* Loads a file from given paths, optionally searching for specific extensions.
|
|
@@ -1064,11 +1281,42 @@ declare function createEndWithRepetitionDetector(repetitionThreshold: number): (
|
|
|
1064
1281
|
*/
|
|
1065
1282
|
declare function loadFileFromPaths(filename: string, searchPaths?: string[], extNames?: string[], options?: {
|
|
1066
1283
|
filepath?: string;
|
|
1284
|
+
exclude?: string[] | string;
|
|
1285
|
+
signal?: AbortSignal;
|
|
1067
1286
|
}): Buffer;
|
|
1068
1287
|
declare function loadTextFromPaths(filename: string, searchPaths?: string[], extNames?: string[], options?: {
|
|
1069
1288
|
encoding?: BufferEncoding;
|
|
1070
1289
|
filepath?: string;
|
|
1071
|
-
|
|
1290
|
+
signal?: AbortSignal;
|
|
1291
|
+
} | BufferEncoding, exclude?: string[] | string): string;
|
|
1292
|
+
/**
|
|
1293
|
+
* Recursively reads all filenames in the given directory or directories.
|
|
1294
|
+
* Optionally filters the results using a file matching callback.
|
|
1295
|
+
*
|
|
1296
|
+
* @param dir - A single directory path or an array of directory paths to start the search from.
|
|
1297
|
+
* @param isFileMatched - An optional callback that determines whether a file should be included in the result.
|
|
1298
|
+
* @returns An array of file paths that match the criteria.
|
|
1299
|
+
*
|
|
1300
|
+
* @example
|
|
1301
|
+
* ```typescript
|
|
1302
|
+
* const files = readFilenamesRecursiveSync('/path/to/directory', (filepath) => filepath.endsWith('.js'));
|
|
1303
|
+
* console.log(files); // Outputs an array of JavaScript file paths.
|
|
1304
|
+
* ```
|
|
1305
|
+
*/
|
|
1306
|
+
declare function readFilenamesRecursiveSync(dir: string | string[], isFileMatched?: (filepath: string) => boolean, signal?: AbortSignal): string[];
|
|
1307
|
+
/**
|
|
1308
|
+
* Resolves the real file path, handling symbolic links.
|
|
1309
|
+
*
|
|
1310
|
+
* @param filepath - The file path to resolve.
|
|
1311
|
+
* @returns The real file path.
|
|
1312
|
+
*
|
|
1313
|
+
* @example
|
|
1314
|
+
* ```typescript
|
|
1315
|
+
* const realPath = getRealFilepath('/path/to/symbolic/link');
|
|
1316
|
+
* console.log(realPath); // Outputs the resolved path.
|
|
1317
|
+
* ```
|
|
1318
|
+
*/
|
|
1319
|
+
declare function getRealFilepath(filepath: string): string;
|
|
1072
1320
|
|
|
1073
1321
|
declare function registerYamlTag(tags: any): void;
|
|
1074
1322
|
declare function parseYaml(content: string): any;
|
|
@@ -1082,7 +1330,7 @@ interface ConfigFilesFilter {
|
|
|
1082
1330
|
}
|
|
1083
1331
|
declare function getConfigFileNames(directoryPath: string, filter?: ConfigFilesFilter): string[];
|
|
1084
1332
|
declare function getConfigs(directoryPath: string, filter?: ConfigFilesFilter): any[];
|
|
1085
|
-
declare function saveConfigFile(filename: string, config: any, extLevel?: number):
|
|
1333
|
+
declare function saveConfigFile(filename: string, config: any, extLevel?: number): string;
|
|
1086
1334
|
|
|
1087
1335
|
interface JsonFilter {
|
|
1088
1336
|
[key: string]: any;
|
|
@@ -1130,4 +1378,72 @@ declare function jsonFilterToWhere(filter: JsonFilter | JsonFilter[], wrapKey?:
|
|
|
1130
1378
|
*/
|
|
1131
1379
|
declare function matchUrlProtocol(name: string): string | undefined;
|
|
1132
1380
|
|
|
1133
|
-
|
|
1381
|
+
/**
|
|
1382
|
+
* Formats a parameter size in bytes into a string with an appropriate scale (T, B, M, or K),
|
|
1383
|
+
* optionally specifying the number of fractional digits to display.
|
|
1384
|
+
*
|
|
1385
|
+
* @param paramsSize The parameter size in bytes.
|
|
1386
|
+
* @param fractionDigits The number of fractional digits to include in the formatted output. Default is 0 (no fractional digits).
|
|
1387
|
+
* @returns A string representing the formatted parameter size with the appropriate scale unit and the specified number of fractional digits.
|
|
1388
|
+
*/
|
|
1389
|
+
declare function paramsSizeToScaleStr(paramsSize: number, fractionDigits?: number): string;
|
|
1390
|
+
/**
|
|
1391
|
+
* Converts a formatted parameters size string (with units T, B, M, or K) back to its byte value.
|
|
1392
|
+
*
|
|
1393
|
+
* @param scale The formatted parameter size string (e.g., "1.23B", "456M", "789K", or "123").
|
|
1394
|
+
* @returns The parameter size in bytes.
|
|
1395
|
+
*/
|
|
1396
|
+
declare function scaleStrToParamsSize(scale: string): number;
|
|
1397
|
+
|
|
1398
|
+
declare function jsonToMarkdownStr(mem: any, options?: {
|
|
1399
|
+
level?: number;
|
|
1400
|
+
visiting?: Set<any>;
|
|
1401
|
+
objectTag?: string;
|
|
1402
|
+
arrayTag?: string;
|
|
1403
|
+
}): string;
|
|
1404
|
+
|
|
1405
|
+
declare function toDateTime(date: Date | string | number): Date | undefined;
|
|
1406
|
+
declare function textToDate(date: string, format?: string): Date;
|
|
1407
|
+
declare function dateToText(date: Date, format?: string): string;
|
|
1408
|
+
|
|
1409
|
+
/**
|
|
1410
|
+
* Represents a set of integers using a bit field.
|
|
1411
|
+
* Each bit in the bit field represents an integer starting from 0,
|
|
1412
|
+
* where the flag value 0 represents the 0th bit, 1 represents the 1st bit, and so on.
|
|
1413
|
+
*/
|
|
1414
|
+
declare class IntSet {
|
|
1415
|
+
private bitField;
|
|
1416
|
+
static has(bitField: number, flag: number): boolean;
|
|
1417
|
+
static add(bitField: number, flag: number): number;
|
|
1418
|
+
static delete(bitField: number, flag: number): number;
|
|
1419
|
+
constructor(bitField?: number);
|
|
1420
|
+
/**
|
|
1421
|
+
* Adds an element to the set.
|
|
1422
|
+
*
|
|
1423
|
+
* @param flag - The flag value representing the bit position to set.
|
|
1424
|
+
* Note: the flag value 0 represents the 0th bit, and so on.
|
|
1425
|
+
*/
|
|
1426
|
+
add(flag: number): this;
|
|
1427
|
+
/**
|
|
1428
|
+
* Removes an element from the set.
|
|
1429
|
+
*
|
|
1430
|
+
* @param flag - The flag value representing the bit position to set. 0 represents the 0th bit
|
|
1431
|
+
*/
|
|
1432
|
+
delete(flag: number): this;
|
|
1433
|
+
/**
|
|
1434
|
+
* Determines whether an element is in the set.
|
|
1435
|
+
*
|
|
1436
|
+
* @param flag - The flag value representing the bit position to set. 0 represents the 0th bit
|
|
1437
|
+
* @returns true if the element is in the set; otherwise, false.
|
|
1438
|
+
*/
|
|
1439
|
+
has(flag: number): boolean;
|
|
1440
|
+
/**
|
|
1441
|
+
* Clears all elements from the set.
|
|
1442
|
+
*/
|
|
1443
|
+
clear(): this;
|
|
1444
|
+
valueOf(): number;
|
|
1445
|
+
toString(): string;
|
|
1446
|
+
toJSON(): number;
|
|
1447
|
+
}
|
|
1448
|
+
|
|
1449
|
+
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, 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 };
|