@isdk/ai-tool 0.0.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 (87) hide show
  1. package/README.cn.md +261 -0
  2. package/README.md +3 -0
  3. package/dist/chunk-EZFPVSGF.mjs +22 -0
  4. package/dist/chunk-PKECBABP.mjs +5085 -0
  5. package/dist/funcs.d.mts +6 -0
  6. package/dist/funcs.d.ts +6 -0
  7. package/dist/funcs.js +5016 -0
  8. package/dist/funcs.mjs +37 -0
  9. package/dist/index-D4KjfAKl.d.mts +606 -0
  10. package/dist/index-D4KjfAKl.d.ts +606 -0
  11. package/dist/index.d.mts +1097 -0
  12. package/dist/index.d.ts +1097 -0
  13. package/dist/index.js +5239 -0
  14. package/dist/index.mjs +399 -0
  15. package/dist/test/util.d.mts +7 -0
  16. package/dist/test/util.d.ts +7 -0
  17. package/dist/test/util.js +98 -0
  18. package/dist/test/util.mjs +61 -0
  19. package/docs/.nojekyll +1 -0
  20. package/docs/README.md +5 -0
  21. package/docs/classes/AbortError.md +359 -0
  22. package/docs/classes/AlreadyExistsError.md +339 -0
  23. package/docs/classes/BaseError.md +346 -0
  24. package/docs/classes/ClientTools.md +2705 -0
  25. package/docs/classes/CommonError.md +368 -0
  26. package/docs/classes/ConfigFile.md +346 -0
  27. package/docs/classes/EventClient.md +3183 -0
  28. package/docs/classes/EventServer.md +3138 -0
  29. package/docs/classes/EventToolFunc.md +2498 -0
  30. package/docs/classes/FStringPromptTemplate.md +1236 -0
  31. package/docs/classes/FewShotPromptTemplate.md +1286 -0
  32. package/docs/classes/GolangPromptTemplate.md +1236 -0
  33. package/docs/classes/HFEnvironment.md +212 -0
  34. package/docs/classes/HFInterpreter.md +386 -0
  35. package/docs/classes/HFTemplate.md +79 -0
  36. package/docs/classes/HfPromptTemplate.md +1236 -0
  37. package/docs/classes/NotFoundError.md +339 -0
  38. package/docs/classes/NotImplementationError.md +339 -0
  39. package/docs/classes/PromptExampleSelector.md +207 -0
  40. package/docs/classes/PromptTemplate.md +1163 -0
  41. package/docs/classes/ReadableStreamError.md +359 -0
  42. package/docs/classes/ResClientTools.md +2859 -0
  43. package/docs/classes/ResServerTools.md +2783 -0
  44. package/docs/classes/SSEChannel.md +289 -0
  45. package/docs/classes/ServerTools.md +2633 -0
  46. package/docs/classes/ToolFunc.md +2124 -0
  47. package/docs/enums/ErrorCode.md +217 -0
  48. package/docs/enums/XXHashAlgorithm.md +30 -0
  49. package/docs/interfaces/AIChatAssistantMessageParam.md +84 -0
  50. package/docs/interfaces/AIChatContentPartImage.md +36 -0
  51. package/docs/interfaces/AIChatContentPartText.md +30 -0
  52. package/docs/interfaces/AIChatMessageParamBase.md +35 -0
  53. package/docs/interfaces/AIChatMessageToolCall.md +48 -0
  54. package/docs/interfaces/AIChatSystemMessageParam.md +51 -0
  55. package/docs/interfaces/AIChatToolMessageParam.md +62 -0
  56. package/docs/interfaces/AIChatUserMessageParam.md +95 -0
  57. package/docs/interfaces/AIResult.md +65 -0
  58. package/docs/interfaces/AIStreamCallbacksAndOptions.md +158 -0
  59. package/docs/interfaces/AIStreamParser.md +33 -0
  60. package/docs/interfaces/AIStreamParserOptions.md +23 -0
  61. package/docs/interfaces/BaseFunc.md +145 -0
  62. package/docs/interfaces/BaseFuncItem.md +99 -0
  63. package/docs/interfaces/ClientFuncItem.md +181 -0
  64. package/docs/interfaces/DotenvExpandOptions.md +51 -0
  65. package/docs/interfaces/DotenvExpandOutput.md +30 -0
  66. package/docs/interfaces/DotenvParseInput.md +7 -0
  67. package/docs/interfaces/DotenvParseOutput.md +7 -0
  68. package/docs/interfaces/DotenvPopulateInput.md +7 -0
  69. package/docs/interfaces/EventClientFuncParams.md +66 -0
  70. package/docs/interfaces/EventServerFuncParams.md +79 -0
  71. package/docs/interfaces/FewShotPromptTemplateOptions.md +179 -0
  72. package/docs/interfaces/FuncItem.md +130 -0
  73. package/docs/interfaces/FuncParam.md +67 -0
  74. package/docs/interfaces/FuncParams.md +7 -0
  75. package/docs/interfaces/Funcs.md +7 -0
  76. package/docs/interfaces/IOptions.md +30 -0
  77. package/docs/interfaces/JsonFilter.md +7 -0
  78. package/docs/interfaces/PromptExampleSelectorOptions.md +39 -0
  79. package/docs/interfaces/PromptTemplateOptions.md +84 -0
  80. package/docs/interfaces/RemoteFuncItem.md +167 -0
  81. package/docs/interfaces/ResClientFuncParams.md +34 -0
  82. package/docs/interfaces/ResServerFuncParams.md +79 -0
  83. package/docs/interfaces/SanitizeFilenameOptions.md +30 -0
  84. package/docs/interfaces/ServerFuncItem.md +192 -0
  85. package/docs/interfaces/ServerFuncParams.md +44 -0
  86. package/docs/modules.md +2707 -0
  87. package/package.json +112 -0
package/dist/funcs.mjs ADDED
@@ -0,0 +1,37 @@
1
+ import {
2
+ EventClient,
3
+ EventServer,
4
+ EventToolFunc,
5
+ _lrucache,
6
+ createLRUCache,
7
+ event,
8
+ eventClient,
9
+ eventServer,
10
+ getDefaultSimilarPassingScore,
11
+ isSimilar,
12
+ lrucache,
13
+ mergeSegments,
14
+ registerCoreTools,
15
+ segments,
16
+ similarity,
17
+ splitSegments
18
+ } from "./chunk-PKECBABP.mjs";
19
+ import "./chunk-EZFPVSGF.mjs";
20
+ export {
21
+ EventClient,
22
+ EventServer,
23
+ EventToolFunc,
24
+ _lrucache,
25
+ createLRUCache,
26
+ event,
27
+ eventClient,
28
+ eventServer,
29
+ getDefaultSimilarPassingScore,
30
+ isSimilar,
31
+ lrucache,
32
+ mergeSegments,
33
+ registerCoreTools,
34
+ segments,
35
+ similarity,
36
+ splitSegments
37
+ };
@@ -0,0 +1,606 @@
1
+ import { EventEmitter, Event } from 'events-ex';
2
+ import { AdvancePropertyManager } from 'property-manager';
3
+ import { ICacheOptions, Cache } from 'secondary-cache';
4
+ import { IncomingMessage, ServerResponse } from 'http';
5
+ import { AbstractError } from 'abstract-error';
6
+
7
+ type FuncParamType = string;
8
+ interface FuncParam {
9
+ name?: string;
10
+ type?: FuncParamType;
11
+ required?: boolean;
12
+ description?: string;
13
+ depends?: {
14
+ [name: string]: ToolFunc;
15
+ };
16
+ }
17
+ interface FuncParams {
18
+ [name: string]: FuncParam | FuncParamType;
19
+ }
20
+ type TFunc = (this: ToolFunc, ...params: any[]) => any;
21
+ interface BaseFuncItem {
22
+ name?: string;
23
+ params?: FuncParams | FuncParam[];
24
+ result?: string;
25
+ scope?: any;
26
+ tags?: string | string[];
27
+ setup?: (this: ToolFunc, options?: FuncItem) => void;
28
+ }
29
+ interface FuncItem extends BaseFuncItem {
30
+ func?: TFunc;
31
+ }
32
+ interface BaseFunc extends BaseFuncItem {
33
+ func(...params: any): any;
34
+ }
35
+ interface Funcs {
36
+ [name: string]: ToolFunc;
37
+ }
38
+ declare interface ToolFunc extends BaseFunc {
39
+ [name: string]: any;
40
+ }
41
+ declare class ToolFunc extends AdvancePropertyManager {
42
+ static items: Funcs;
43
+ static dataPath: string;
44
+ static get(name: string): ToolFunc;
45
+ static list(): Funcs;
46
+ static getByTag(tagName: string): ToolFunc | undefined;
47
+ static getAllByTag(tagName: string): ToolFunc[];
48
+ static run(name: string, params?: any): Promise<any>;
49
+ static runSync(name: string, params?: any): any;
50
+ static getFunc(name: string): any;
51
+ static runWithPos(name: string, ...params: any[]): Promise<any>;
52
+ static runWithPosSync(name: string, ...params: any[]): any;
53
+ static getFuncWithPos(name: string): any;
54
+ static register(name: string, options: FuncItem): boolean | ToolFunc;
55
+ static register(func: Function, options: FuncItem): boolean | ToolFunc;
56
+ static register(name: string | ToolFunc | Function | FuncItem, options?: FuncItem): boolean | ToolFunc;
57
+ static unregister(name: string): ToolFunc | undefined;
58
+ constructor(name: string | Function | FuncItem, options?: FuncItem | any);
59
+ register(): boolean | ToolFunc;
60
+ unregister(): any;
61
+ arr2ObjParams(params: any[]): any[];
62
+ obj2ArrParams(params?: any): any[];
63
+ runSync(params?: any): any;
64
+ run(params?: any): Promise<any>;
65
+ runAs(name: string, params?: any): Promise<any>;
66
+ runAsSync(name: string, params?: any): any;
67
+ getFunc(name?: string): any;
68
+ runWithPosSync(...params: any[]): any;
69
+ runWithPosAsSync(name: string, ...params: any[]): any;
70
+ runWithPos(...params: any[]): Promise<any>;
71
+ runWithPosAs(name: string, ...params: any[]): Promise<any>;
72
+ getFuncWithPos(name?: string): any;
73
+ }
74
+ declare const ToolFuncSchema: {
75
+ name: {
76
+ type: string;
77
+ };
78
+ description: {
79
+ type: string;
80
+ };
81
+ func: {
82
+ type: string;
83
+ assign(value: Function | string, dest: ToolFunc, src?: ToolFunc, name?: string, options?: any): string | Function;
84
+ };
85
+ params: {
86
+ type: string;
87
+ };
88
+ result: {
89
+ type: string;
90
+ };
91
+ setup: {
92
+ type: string;
93
+ };
94
+ depends: {
95
+ type: string;
96
+ exported: boolean;
97
+ };
98
+ tags: {
99
+ type: string[];
100
+ };
101
+ };
102
+
103
+ declare const PASSING_SCORE = 0.618;
104
+ declare const ActionNames: readonly ["get", "post", "put", "delete", "patch", "list", "res"];
105
+ type ActionName = typeof ActionNames[number];
106
+ type AIModelNameRuleFn = (name: string) => string | RegExpExecArray | undefined;
107
+ type AIModelNameRule = string | RegExp | AIModelNameRuleFn;
108
+ type AIModelNameRules = AIModelNameRule | AIModelNameRule[];
109
+ declare const RemoteToolFuncSchema: {
110
+ apiRoot: {
111
+ type: string;
112
+ get(this: any): any;
113
+ set(this: any, value: string): void;
114
+ };
115
+ action: {
116
+ type: string;
117
+ assign(value: ActionName, dest: any, src?: any, name?: string, options?: any): "get" | "post" | "put" | "delete" | "patch" | "list" | "res";
118
+ };
119
+ fetchOptions: {
120
+ type: string;
121
+ };
122
+ allowExportFunc: {
123
+ type: string;
124
+ };
125
+ stream: {
126
+ type: string;
127
+ };
128
+ };
129
+ interface RemoteFuncItem extends BaseFuncItem {
130
+ apiRoot?: string;
131
+ action?: ActionName;
132
+ fetchOptions?: any;
133
+ stream?: boolean;
134
+ }
135
+
136
+ type ErrorCodeType = number | string;
137
+ declare enum ErrorCode {
138
+ OK = 200,
139
+ BadRequest = 400,
140
+ InvalidArgument = 400,
141
+ Unauthorized = 401,
142
+ PaymentRequired = 402,
143
+ Forbidden = 403,
144
+ NotFound = 404,
145
+ MethodNotAllowed = 405,
146
+ NotAcceptable = 406,
147
+ RequestTimeout = 408,
148
+ Conflict = 409,
149
+ Corruption = 409,
150
+ Aborted = 499,
151
+ InternalError = 500,
152
+ NotImplemented = 501,
153
+ NotSupported = 501,
154
+ BadGateway = 502,
155
+ ServiceUnavailable = 503,
156
+ GatewayTimeout = 504
157
+ }
158
+ declare const InternalErrorCode = ErrorCode.InternalError;
159
+ declare const NotImplementedErrorCode = ErrorCode.NotImplemented;
160
+ declare const NotFoundErrorCode = ErrorCode.NotFound;
161
+ declare const AlreadyExistsErrorCode = ErrorCode.Conflict;
162
+ declare const AbortErrorCode = ErrorCode.Aborted;
163
+ /**
164
+ * BaseError class that extends the Error class.
165
+ *
166
+ * @example
167
+ * // Create a custom error
168
+ * class CustomError extends BaseError {
169
+ * static code = 'customError';
170
+ * constructor(message: string) {
171
+ * super(message);
172
+ * }
173
+ * }
174
+ *
175
+ * // Throw the custom error
176
+ * throw new CustomError('This is a custom error');
177
+ *
178
+ * @description
179
+ * This class is used to create custom errors that extend the built-in Error class. It provides a way to define custom error codes and additional data associated with the error.
180
+ *
181
+ * @property {ErrorCodeType} code - The error code associated with the error.
182
+ * @property {string} caller - The name of the function that threw the error.
183
+ * @property {ErrorCodeType} code - The error code associated with the error.
184
+ * @property {any} data - Additional data associated with the error.
185
+ *
186
+ * @method toJSON - Returns a JSON representation of the error.
187
+ * @method fromJSON - Creates a new BaseError instance from a JSON representation.
188
+ */
189
+ declare class BaseError extends AbstractError {
190
+ /**
191
+ * The error code associated with the error.
192
+ */
193
+ static code: ErrorCodeType;
194
+ caller: string;
195
+ code: ErrorCodeType;
196
+ data?: any;
197
+ static createErrorClass(aType: string, aErrorCode?: number | string | typeof AbstractError, ParentErrorClass?: typeof BaseError): typeof BaseError;
198
+ /**
199
+ * Constructs a new BaseError instance.
200
+ *
201
+ * @param {string} message - The error message.
202
+ * @param {ErrorCodeType} [code] - The error code.
203
+ * @param {string|object} [name] - The error name or additional properties.
204
+ */
205
+ constructor(message: string, code?: ErrorCodeType, name?: string | object);
206
+ /**
207
+ * Returns a JSON representation of the error.
208
+ *
209
+ * @returns {object} A JSON representation of the error.
210
+ */
211
+ toJSON(): any;
212
+ /**
213
+ * Creates a new BaseError instance from a JSON representation.
214
+ *
215
+ * @param {object} json - A JSON representation of the error.
216
+ * @returns {BaseError} A new BaseError instance.
217
+ */
218
+ fromJSON(json: any): BaseError;
219
+ }
220
+ declare class CommonError extends BaseError {
221
+ constructor(message: string, name?: string | Record<string, any>, status?: ErrorCodeType);
222
+ }
223
+ /**
224
+ * Represents an error when a function or method is not implemented.
225
+ * Inherits from BaseError.
226
+ *
227
+ * @example
228
+ * throw new NotImplementationError()
229
+ *
230
+ * @extends CommonError
231
+ */
232
+ declare class NotImplementationError extends CommonError {
233
+ constructor(msg?: string, name?: string | Record<string, any>);
234
+ }
235
+ /**
236
+ * Represents an error when a requested resource is not found.
237
+ * Inherits from BaseError.
238
+ *
239
+ * @example
240
+ * throw new NotFoundError('user', { id: 123 })
241
+ *
242
+ * @extends CommonError
243
+ */
244
+ declare class NotFoundError extends CommonError {
245
+ static code: ErrorCode;
246
+ constructor(what: string | number, name?: string | Record<string, any>);
247
+ }
248
+ /**
249
+ * Represents an error when a requested resource already exists.
250
+ * Inherits from BaseError.
251
+ *
252
+ * @example
253
+ * throw new AlreadyExistsError('user', { id: 123 })
254
+ *
255
+ * @extends CommonError
256
+ */
257
+ declare class AlreadyExistsError extends CommonError {
258
+ static code: ErrorCode;
259
+ constructor(what: string | number, name?: string | Record<string, any>);
260
+ }
261
+ declare class AbortError extends CommonError {
262
+ static code: ErrorCode;
263
+ constructor(what?: string, name?: string | Record<string, any>);
264
+ }
265
+ /**
266
+ * Create an error object
267
+ * @param message - Error message
268
+ * @param name - Error name, optional
269
+ * @param status - Error status code, default to 500
270
+ * @returns Error object
271
+ */
272
+ declare function createError(message: string, name?: string | Record<string, any>, status?: ErrorCode | ErrorCodeType): CommonError;
273
+ /**
274
+ * Throw an error
275
+ * @param message - Error message
276
+ * @param name - Error name, optional
277
+ * @param status - Error status code, default to 500
278
+ * @throws {BaseError} Throws a BaseError object
279
+ */
280
+ declare function throwError(message: string, name?: string | Record<string, any>, status?: ErrorCode | ErrorCodeType): void;
281
+
282
+ type Events = (string | RegExp)[];
283
+ type Client = {
284
+ req: IncomingMessage;
285
+ res: ServerResponse;
286
+ events?: Events;
287
+ };
288
+ declare const SSEChannelAlreadyClosedErrCode = 498;
289
+ /**
290
+ * A class for creating Server-Sent Events (SSE) channels.
291
+ * @example
292
+ * const sseChannel = new SSEChannel({ pingInterval: 5000 })
293
+ * sseChannel.publish('Hello, world!', 'greeting')
294
+ */
295
+ declare class SSEChannel {
296
+ _active: boolean;
297
+ clients: Set<Client>;
298
+ messages: Record<string, any>[];
299
+ nextID: number;
300
+ options: Record<string, any>;
301
+ pingTimer?: NodeJS.Timeout;
302
+ get active(): boolean;
303
+ set active(v: boolean);
304
+ /**
305
+ * Creates a new SSE channel.
306
+ * @param options - The options for the SSE channel.
307
+ */
308
+ constructor(options?: Record<string, any>);
309
+ /**
310
+ * Publishes a message to the SSE channel.
311
+ * @param {string | Record<string, any>} data - The data to send. It can be a string or an object.
312
+ * @param {string} eventName - The name of the event.
313
+ * @returns {number | undefined} - Returns the ID of the message.
314
+ * @throws Will throw an error if the channel is closed.
315
+ */
316
+ publish(data?: string | Record<string, any>, eventName?: string): number | undefined;
317
+ /**
318
+ * Subscribes a client to the SSE channel.
319
+ * @param {IncomingMessage} req - The request object.
320
+ * @param {ServerResponse} res - The response object.
321
+ * @param {Events} events - The events to subscribe to.
322
+ * @returns {Client} - Returns the client object.
323
+ * @throws Will throw an error if the channel is closed.
324
+ */
325
+ subscribe(req: IncomingMessage, res: ServerResponse, events?: Events): {
326
+ req: IncomingMessage;
327
+ res: ServerResponse<IncomingMessage>;
328
+ events: Events | undefined;
329
+ };
330
+ /**
331
+ * Unsubscribes a client from the SSE channel.
332
+ * @param {Client} c - The client to unsubscribe.
333
+ */
334
+ unsubscribe(c: Client): void;
335
+ clearClients(): void;
336
+ /**
337
+ * Lists the clients connected to the SSE channel grouped by IP address.
338
+ * @returns - Returns an object where the keys are the IP addresses and the values are the number of clients connected from each IP.
339
+ */
340
+ listClients(): Record<string, number>;
341
+ /**
342
+ * Gets the number of clients subscribed to the SSE channel.
343
+ * @returns - Returns the number of clients.
344
+ */
345
+ getSubscriberCount(): number;
346
+ }
347
+
348
+ interface ClientFuncItem extends RemoteFuncItem {
349
+ }
350
+ declare interface ClientTools extends ClientFuncItem {
351
+ [name: string]: any;
352
+ }
353
+ declare class ClientTools extends ToolFunc {
354
+ apiRoot: string | undefined;
355
+ private static _apiRoot?;
356
+ static get apiRoot(): string | undefined;
357
+ static setApiRoot(v: string): void;
358
+ static loadFrom(): Promise<void>;
359
+ static loadFromSync(items: Funcs): void;
360
+ static fetch(name: string, objParam?: any): Promise<any>;
361
+ getUrlParams(objParam: any): string;
362
+ fetch(objParam?: any, act?: ActionName, subName?: any): Promise<Response>;
363
+ errorFrom(res: Response): Promise<CommonError>;
364
+ func(objParam: any): Promise<any>;
365
+ }
366
+ declare const ClientToolFuncSchema: {
367
+ apiRoot: {
368
+ type: string;
369
+ get(this: any): any;
370
+ set(this: any, value: string): void;
371
+ };
372
+ action: {
373
+ type: string;
374
+ assign(value: "get" | "post" | "put" | "delete" | "patch" | "list" | "res", dest: any, src?: any, name?: string | undefined, options?: any): "get" | "post" | "put" | "delete" | "patch" | "list" | "res";
375
+ };
376
+ fetchOptions: {
377
+ type: string;
378
+ };
379
+ allowExportFunc: {
380
+ type: string;
381
+ };
382
+ stream: {
383
+ type: string;
384
+ };
385
+ };
386
+
387
+ /**
388
+ * Convention: Always pass _req, _res
389
+ */
390
+ interface ServerFuncParams {
391
+ _req?: IncomingMessage;
392
+ _res?: ServerResponse;
393
+ [name: string]: any;
394
+ }
395
+ interface ServerFuncItem extends RemoteFuncItem {
396
+ allowExportFunc?: boolean;
397
+ }
398
+ declare interface ServerTools extends ServerFuncItem {
399
+ [name: string]: any;
400
+ }
401
+ declare class ServerTools extends ToolFunc {
402
+ private static _apiRoot?;
403
+ static get apiRoot(): string | undefined;
404
+ static setApiRoot(v: string): void;
405
+ static toJSON(): {
406
+ [name: string]: ServerTools;
407
+ };
408
+ isStream(params: ServerFuncParams): boolean | undefined;
409
+ func({}: {}): Promise<any> | any;
410
+ }
411
+ declare const ServerToolFuncSchema: {
412
+ apiRoot: {
413
+ type: string;
414
+ get(this: any): any;
415
+ set(this: any, value: string): void;
416
+ };
417
+ action: {
418
+ type: string;
419
+ assign(value: "get" | "post" | "put" | "delete" | "patch" | "list" | "res", dest: any, src?: any, name?: string | undefined, options?: any): "get" | "post" | "put" | "delete" | "patch" | "list" | "res";
420
+ };
421
+ fetchOptions: {
422
+ type: string;
423
+ };
424
+ allowExportFunc: {
425
+ type: string;
426
+ };
427
+ stream: {
428
+ type: string;
429
+ };
430
+ };
431
+
432
+ declare class EventToolFunc extends ToolFunc {
433
+ _emitter: EventEmitter;
434
+ description: string;
435
+ result: string;
436
+ get emitter(): EventEmitter;
437
+ func(): EventEmitter;
438
+ }
439
+ declare const event: EventToolFunc;
440
+
441
+ declare function _lrucache(this: ToolFunc, { key, value, options }?: {
442
+ key?: string;
443
+ value?: any;
444
+ options?: ICacheOptions | number;
445
+ }): Cache;
446
+ declare function createLRUCache(name: string, options?: ICacheOptions | number): ToolFunc;
447
+ declare const lrucache: ToolFunc;
448
+
449
+ declare const similarity: ServerTools;
450
+
451
+ declare function getDefaultSimilarPassingScore(modelId: string): number;
452
+ declare const isSimilar: ServerTools;
453
+
454
+ declare const splitSegments: ServerTools;
455
+
456
+ declare const mergeSegments: ServerTools;
457
+
458
+ declare const segments: ServerTools;
459
+
460
+ interface ResClientFuncParams {
461
+ id?: string | number;
462
+ act?: string;
463
+ [name: string]: any;
464
+ }
465
+ interface ResClientTools {
466
+ get?({ id }: ResClientFuncParams): any;
467
+ post?(options: ResClientFuncParams): any;
468
+ put?({ id }: ResClientFuncParams): any;
469
+ delete?({ id }: ResClientFuncParams): any;
470
+ list?(options: ResClientFuncParams): any;
471
+ }
472
+ declare class ResClientTools extends ClientTools {
473
+ fetch(options: ResClientFuncParams, action: ActionName): Promise<Response>;
474
+ _func(action: ActionName, options: ResClientFuncParams): Promise<any>;
475
+ func(options: ResClientFuncParams): Promise<any>;
476
+ assignMethods(methods: string[]): void;
477
+ }
478
+ declare const ResClientToolsSchema: {
479
+ methods: {
480
+ type: string;
481
+ assign(value: string[], dest: any, src?: any, name?: string, options?: any): void;
482
+ };
483
+ };
484
+
485
+ interface EventClientFuncParams {
486
+ event?: string | string[];
487
+ data?: any;
488
+ act?: 'sub' | 'pub' | 'unsub' | 'init';
489
+ listener?: (...args: any[]) => void;
490
+ }
491
+ declare class EventClient extends ResClientTools {
492
+ _es: EventSource | undefined;
493
+ _esEvents: string[] | undefined;
494
+ _sseEvents: Record<string, (e: MessageEvent) => void>;
495
+ _forwardEvents: Set<string>;
496
+ get evtSource(): EventSource;
497
+ get active(): boolean;
498
+ set active(v: boolean);
499
+ name: string;
500
+ description: string;
501
+ initEventSource(events?: string | string[]): EventSource;
502
+ esListener(event: MessageEvent): void;
503
+ ebListener: (this: Event, ...data: any[]) => Promise<void>;
504
+ /**
505
+ * subscribe server sent event(SSE)
506
+ * @param events
507
+ */
508
+ subscribe(events: string | string[]): Promise<any>;
509
+ /**
510
+ * unsubscribe server sent event(SSE)
511
+ * @param events
512
+ */
513
+ unsubscribe(events: string | string[]): Promise<any>;
514
+ /**
515
+ * forward local event(s) to server
516
+ *
517
+ * subscribe these local events to forward/publish to server
518
+ *
519
+ * Note: pls backendEventable(ClientTools or EventClient) first
520
+ * @param events
521
+ */
522
+ forwardEvent(events: string | string[]): void;
523
+ /**
524
+ * unforward local event(s) to server
525
+ *
526
+ * unsubscribe these local events not to forward/publish to server
527
+ *
528
+ * Note: pls backendEventable(ClientTools or EventClient) first
529
+ * @param events
530
+ */
531
+ unforwardEvent(events: string | string[]): void;
532
+ init(events: string | string[]): Promise<any>;
533
+ }
534
+ declare const eventClient: EventClient;
535
+
536
+ interface ResServerFuncParams extends ServerFuncParams {
537
+ id?: string | number;
538
+ val?: any;
539
+ act?: string;
540
+ }
541
+ interface ResServerTools {
542
+ methods: string[];
543
+ get?({ id }: ResServerFuncParams): any;
544
+ post?(options: ResServerFuncParams): any;
545
+ put?({ id }: ResServerFuncParams): any;
546
+ delete?({ id }: ResServerFuncParams): any;
547
+ list?(options?: ResServerFuncParams): any;
548
+ }
549
+ declare class ResServerTools extends ServerTools {
550
+ action: ActionName;
551
+ params: FuncParams;
552
+ constructor(name: string | Function | FuncItem, options?: FuncItem | any);
553
+ cast(key: string, value: any): any;
554
+ getMethodFromParams(params: ResServerFuncParams): string | undefined;
555
+ func(params: ResServerFuncParams): any;
556
+ }
557
+ declare const ResServerToolsSchema: {
558
+ methods: {
559
+ type: string;
560
+ };
561
+ };
562
+
563
+ interface EventServerFuncParams extends ServerFuncParams {
564
+ event?: string | string[];
565
+ data?: any;
566
+ act?: 'sub' | 'pub' | 'unsub';
567
+ }
568
+ declare class EventServer extends ResServerTools {
569
+ static _sse: SSEChannel | undefined;
570
+ static get sse(): SSEChannel;
571
+ name: string;
572
+ description: string;
573
+ result: string;
574
+ depends: {
575
+ "event-bus": EventToolFunc;
576
+ };
577
+ get sse(): any;
578
+ static publish(data: any, event: string): number | undefined;
579
+ static ebListener: (this: Event, ...data: any[]) => void;
580
+ static subscribe(req: IncomingMessage, res: ServerResponse, events?: string[]): {
581
+ req: IncomingMessage;
582
+ res: ServerResponse<IncomingMessage>;
583
+ events: (string | RegExp)[] | undefined;
584
+ };
585
+ static alreadyForward(event: string): true | undefined;
586
+ publishSSE(data: any, event: string): any;
587
+ subscribeSSE(req: IncomingMessage, res: ServerResponse, events?: string | string[]): any;
588
+ forward(events: string | string[]): void;
589
+ unforward(events: string | string[]): void;
590
+ list({ _req, _res, event }: EventServerFuncParams): void;
591
+ $sub({ event }: EventServerFuncParams): {
592
+ event: string | string[];
593
+ } | undefined;
594
+ $unsub({ event }: EventServerFuncParams): {
595
+ event: string | string[];
596
+ } | undefined;
597
+ $publish({ event: events, data }: EventServerFuncParams): {
598
+ event: string[];
599
+ } | undefined;
600
+ isStream(params: ServerFuncParams): boolean;
601
+ }
602
+ declare const eventServer: EventServer;
603
+
604
+ declare function registerCoreTools(): void;
605
+
606
+ export { segments as $, type AIModelNameRules as A, BaseError as B, CommonError as C, ClientToolFuncSchema as D, type ErrorCodeType as E, type FuncParamType as F, type ServerFuncParams as G, type ServerFuncItem as H, InternalErrorCode as I, ServerTools as J, ServerToolFuncSchema as K, registerCoreTools as L, EventToolFunc as M, NotImplementedErrorCode as N, event as O, PASSING_SCORE as P, createLRUCache as Q, RemoteToolFuncSchema as R, SSEChannelAlreadyClosedErrCode as S, type TFunc as T, lrucache as U, similarity as V, getDefaultSimilarPassingScore as W, isSimilar as X, splitSegments as Y, mergeSegments as Z, _lrucache as _, ActionNames as a, type EventClientFuncParams as a0, EventClient as a1, eventClient as a2, type EventServerFuncParams as a3, EventServer as a4, eventServer as a5, type ResClientFuncParams as a6, ResClientTools as a7, ResClientToolsSchema as a8, type ResServerFuncParams as a9, ResServerTools as aa, ResServerToolsSchema as ab, type ActionName as b, type AIModelNameRuleFn as c, type AIModelNameRule as d, type RemoteFuncItem as e, ErrorCode as f, NotFoundErrorCode as g, AlreadyExistsErrorCode as h, AbortErrorCode as i, NotImplementationError as j, NotFoundError as k, AlreadyExistsError as l, AbortError as m, createError as n, SSEChannel as o, type FuncParam as p, type FuncParams as q, type BaseFuncItem as r, type FuncItem as s, throwError as t, type BaseFunc as u, type Funcs as v, ToolFunc as w, ToolFuncSchema as x, type ClientFuncItem as y, ClientTools as z };