vovk 3.0.0-draft.212 → 3.0.0-draft.213

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.
@@ -1,7 +1,21 @@
1
1
  import type { KnownAny, VovkHandlerSchema, VovkLLMFunction } from '../types';
2
+ type Handler = ((...args: KnownAny[]) => KnownAny) & {
3
+ fn?: (input: KnownAny) => KnownAny;
4
+ isRPC?: boolean;
5
+ schema?: VovkHandlerSchema;
6
+ };
7
+ type CallerInput = {
8
+ handler: Handler;
9
+ body: KnownAny;
10
+ query: KnownAny;
11
+ params: KnownAny;
12
+ schema: VovkHandlerSchema;
13
+ handlerName: string;
14
+ rpcModuleName: string;
15
+ };
2
16
  declare function defaultCaller({ handler, body, query, params, }: {
3
17
  handler: ((...args: KnownAny[]) => KnownAny) & {
4
- func?: (req: KnownAny) => KnownAny;
18
+ fn?: (req: KnownAny) => KnownAny;
5
19
  isRPC?: boolean;
6
20
  };
7
21
  body: KnownAny;
@@ -9,11 +23,11 @@ declare function defaultCaller({ handler, body, query, params, }: {
9
23
  params: KnownAny;
10
24
  schema: VovkHandlerSchema;
11
25
  }, _options: KnownAny): Promise<any>;
12
- export declare function createLLMFunctions({ modules, caller, onSuccess, onError, }: {
26
+ export declare function createLLMFunctions({ modules, caller, onExecute, onError, }: {
13
27
  modules: Record<string, unknown>;
14
28
  caller?: typeof defaultCaller;
15
- onSuccess?: (result: KnownAny) => void;
16
- onError?: (error: Error) => void;
29
+ onExecute?: (result: KnownAny, callerInput: CallerInput, options: KnownAny) => void;
30
+ onError?: (error: Error, callerInput: CallerInput, options: KnownAny) => void;
17
31
  }): {
18
32
  functions: VovkLLMFunction[];
19
33
  };
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createLLMFunctions = createLLMFunctions;
4
- const createLLMFunction = ({ rpcModuleName, handlerName, caller, modules, onSuccess, onError, }) => {
4
+ const createLLMFunction = ({ rpcModuleName, handlerName, caller, modules, onExecute, onError, }) => {
5
5
  const module = modules[rpcModuleName];
6
6
  if (!module) {
7
7
  throw new Error(`Module "${rpcModuleName}" not found.`);
@@ -16,15 +16,18 @@ const createLLMFunction = ({ rpcModuleName, handlerName, caller, modules, onSucc
16
16
  }
17
17
  const execute = (input, options) => {
18
18
  const { body, query, params } = input;
19
- return caller({
19
+ const callerInput = {
20
20
  schema,
21
21
  handler,
22
22
  body,
23
23
  query,
24
24
  params,
25
- }, options)
26
- .then((data) => onSuccess(data) ?? data)
27
- .catch((error) => onError?.(error) ?? error);
25
+ handlerName,
26
+ rpcModuleName,
27
+ };
28
+ return caller(callerInput, options)
29
+ .then((data) => onExecute(data, callerInput, options) ?? data)
30
+ .catch((error) => onError?.(error, callerInput, options) ?? error);
28
31
  };
29
32
  const parametersProperties = {
30
33
  ...(schema?.validation?.body
@@ -70,8 +73,8 @@ _options) {
70
73
  params,
71
74
  });
72
75
  }
73
- if (handler.func) {
74
- return handler.func({
76
+ if (handler.fn) {
77
+ return handler.fn({
75
78
  body,
76
79
  query,
77
80
  params,
@@ -79,7 +82,7 @@ _options) {
79
82
  }
80
83
  throw new Error('Handler is not a valid RPC or controller method');
81
84
  }
82
- function createLLMFunctions({ modules, caller = defaultCaller, onSuccess = (result) => result, onError = () => { }, }) {
85
+ function createLLMFunctions({ modules, caller = defaultCaller, onExecute = (result) => result, onError = () => { }, }) {
83
86
  const functions = Object.entries(modules ?? {})
84
87
  .map(([rpcModuleName, module]) => {
85
88
  return Object.entries(module ?? {})
@@ -89,7 +92,7 @@ function createLLMFunctions({ modules, caller = defaultCaller, onSuccess = (resu
89
92
  handlerName,
90
93
  caller,
91
94
  modules,
92
- onSuccess,
95
+ onExecute,
93
96
  onError,
94
97
  }));
95
98
  })
@@ -1,7 +1,21 @@
1
1
  import type { KnownAny, VovkHandlerSchema, VovkLLMFunction } from '../types';
2
+ type Handler = ((...args: KnownAny[]) => KnownAny) & {
3
+ fn?: (input: KnownAny) => KnownAny;
4
+ isRPC?: boolean;
5
+ schema?: VovkHandlerSchema;
6
+ };
7
+ type CallerInput = {
8
+ handler: Handler;
9
+ body: KnownAny;
10
+ query: KnownAny;
11
+ params: KnownAny;
12
+ schema: VovkHandlerSchema;
13
+ handlerName: string;
14
+ rpcModuleName: string;
15
+ };
2
16
  declare function defaultCaller({ handler, body, query, params, }: {
3
17
  handler: ((...args: KnownAny[]) => KnownAny) & {
4
- func?: (req: KnownAny) => KnownAny;
18
+ fn?: (req: KnownAny) => KnownAny;
5
19
  isRPC?: boolean;
6
20
  };
7
21
  body: KnownAny;
@@ -9,11 +23,11 @@ declare function defaultCaller({ handler, body, query, params, }: {
9
23
  params: KnownAny;
10
24
  schema: VovkHandlerSchema;
11
25
  }, _options: KnownAny): Promise<any>;
12
- export declare function createLLMFunctions({ modules, caller, onSuccess, onError, }: {
26
+ export declare function createLLMFunctions({ modules, caller, onExecute, onError, }: {
13
27
  modules: Record<string, unknown>;
14
28
  caller?: typeof defaultCaller;
15
- onSuccess?: (result: KnownAny) => void;
16
- onError?: (error: Error) => void;
29
+ onExecute?: (result: KnownAny, callerInput: CallerInput, options: KnownAny) => void;
30
+ onError?: (error: Error, callerInput: CallerInput, options: KnownAny) => void;
17
31
  }): {
18
32
  functions: VovkLLMFunction[];
19
33
  };
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createLLMFunctions = createLLMFunctions;
4
- const createLLMFunction = ({ rpcModuleName, handlerName, caller, modules, onSuccess, onError, }) => {
4
+ const createLLMFunction = ({ rpcModuleName, handlerName, caller, modules, onExecute, onError, }) => {
5
5
  const module = modules[rpcModuleName];
6
6
  if (!module) {
7
7
  throw new Error(`Module "${rpcModuleName}" not found.`);
@@ -16,15 +16,18 @@ const createLLMFunction = ({ rpcModuleName, handlerName, caller, modules, onSucc
16
16
  }
17
17
  const execute = (input, options) => {
18
18
  const { body, query, params } = input;
19
- return caller({
19
+ const callerInput = {
20
20
  schema,
21
21
  handler,
22
22
  body,
23
23
  query,
24
24
  params,
25
- }, options)
26
- .then((data) => onSuccess(data) ?? data)
27
- .catch((error) => onError?.(error) ?? error);
25
+ handlerName,
26
+ rpcModuleName,
27
+ };
28
+ return caller(callerInput, options)
29
+ .then((data) => onExecute(data, callerInput, options) ?? data)
30
+ .catch((error) => onError?.(error, callerInput, options) ?? error);
28
31
  };
29
32
  const parametersProperties = {
30
33
  ...(schema?.validation?.body
@@ -70,8 +73,8 @@ _options) {
70
73
  params,
71
74
  });
72
75
  }
73
- if (handler.func) {
74
- return handler.func({
76
+ if (handler.fn) {
77
+ return handler.fn({
75
78
  body,
76
79
  query,
77
80
  params,
@@ -79,7 +82,7 @@ _options) {
79
82
  }
80
83
  throw new Error('Handler is not a valid RPC or controller method');
81
84
  }
82
- function createLLMFunctions({ modules, caller = defaultCaller, onSuccess = (result) => result, onError = () => { }, }) {
85
+ function createLLMFunctions({ modules, caller = defaultCaller, onExecute = (result) => result, onError = () => { }, }) {
83
86
  const functions = Object.entries(modules ?? {})
84
87
  .map(([rpcModuleName, module]) => {
85
88
  return Object.entries(module ?? {})
@@ -89,7 +92,7 @@ function createLLMFunctions({ modules, caller = defaultCaller, onSuccess = (resu
89
92
  handlerName,
90
93
  caller,
91
94
  modules,
92
- onSuccess,
95
+ onExecute,
93
96
  onError,
94
97
  }));
95
98
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vovk",
3
- "version": "3.0.0-draft.212",
3
+ "version": "3.0.0-draft.213",
4
4
  "main": "./cjs/index.js",
5
5
  "module": "./mjs/index.js",
6
6
  "types": "./mjs/index.d.ts",