@llmbridge/plugin-logging 0.0.4 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +14 -14
- package/dist/index.d.ts +14 -14
- package/dist/index.js +22 -13
- package/dist/index.mjs +22 -13
- package/package.json +7 -5
package/dist/index.d.mts
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
import { LLMBridge } from '@llmbridge/core';
|
|
2
2
|
|
|
3
|
+
interface Logger {
|
|
4
|
+
log?(message?: any, ...optionalParams: any[]): void;
|
|
5
|
+
info?(message?: any, ...optionalParams: any[]): void;
|
|
6
|
+
warn?(message?: any, ...optionalParams: any[]): void;
|
|
7
|
+
error?(message?: any, ...optionalParams: any[]): void;
|
|
8
|
+
debug?(message?: any, ...optionalParams: any[]): void;
|
|
9
|
+
}
|
|
3
10
|
interface LoggingPluginOptions {
|
|
4
11
|
folder: string;
|
|
12
|
+
logger?: Logger;
|
|
5
13
|
}
|
|
6
14
|
declare function generateRandomDigits(length: number): string;
|
|
7
15
|
declare class LoggingPlugin implements LLMBridge.Plugin<void, string, void, void> {
|
|
8
16
|
private options;
|
|
17
|
+
private logger;
|
|
9
18
|
constructor(options: LoggingPluginOptions);
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
beforeExec(params: any): Promise<string>;
|
|
15
|
-
afterExec({ beforeResponse, response }: {
|
|
16
|
-
beforeResponse: string;
|
|
17
|
-
response: any;
|
|
18
|
-
}): Promise<void>;
|
|
19
|
-
beforeToolExec(tool: LLMBridge.Tool, counter: number, input: any, context: LLMBridge.PluginCompletionContext): Promise<void>;
|
|
20
|
-
afterToolExec({ response }: {
|
|
21
|
-
response: any;
|
|
22
|
-
}): Promise<void>;
|
|
19
|
+
private log;
|
|
20
|
+
wrapRun(next: () => Promise<LLMBridge.Response>, context: LLMBridge.PluginCompletionContext): Promise<LLMBridge.Response>;
|
|
21
|
+
wrapExec(next: (params: any) => Promise<any>, params: any, context: LLMBridge.PluginCompletionContext): Promise<any>;
|
|
22
|
+
wrapToolExec(next: (tool: LLMBridge.Tool, counter: number, input: any) => Promise<any>, tool: LLMBridge.Tool, counter: number, input: any, context: LLMBridge.PluginCompletionContext): Promise<any>;
|
|
23
23
|
createLogFiles(requestId: string, type: 'request' | 'response', data: any): void;
|
|
24
24
|
createTxtFile(filePath: string, data: any): void;
|
|
25
25
|
objectToTxt(obj: any, prefix?: string): string;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
export { LoggingPlugin, type LoggingPluginOptions, generateRandomDigits };
|
|
28
|
+
export { type Logger, LoggingPlugin, type LoggingPluginOptions, generateRandomDigits };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
import { LLMBridge } from '@llmbridge/core';
|
|
2
2
|
|
|
3
|
+
interface Logger {
|
|
4
|
+
log?(message?: any, ...optionalParams: any[]): void;
|
|
5
|
+
info?(message?: any, ...optionalParams: any[]): void;
|
|
6
|
+
warn?(message?: any, ...optionalParams: any[]): void;
|
|
7
|
+
error?(message?: any, ...optionalParams: any[]): void;
|
|
8
|
+
debug?(message?: any, ...optionalParams: any[]): void;
|
|
9
|
+
}
|
|
3
10
|
interface LoggingPluginOptions {
|
|
4
11
|
folder: string;
|
|
12
|
+
logger?: Logger;
|
|
5
13
|
}
|
|
6
14
|
declare function generateRandomDigits(length: number): string;
|
|
7
15
|
declare class LoggingPlugin implements LLMBridge.Plugin<void, string, void, void> {
|
|
8
16
|
private options;
|
|
17
|
+
private logger;
|
|
9
18
|
constructor(options: LoggingPluginOptions);
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
beforeExec(params: any): Promise<string>;
|
|
15
|
-
afterExec({ beforeResponse, response }: {
|
|
16
|
-
beforeResponse: string;
|
|
17
|
-
response: any;
|
|
18
|
-
}): Promise<void>;
|
|
19
|
-
beforeToolExec(tool: LLMBridge.Tool, counter: number, input: any, context: LLMBridge.PluginCompletionContext): Promise<void>;
|
|
20
|
-
afterToolExec({ response }: {
|
|
21
|
-
response: any;
|
|
22
|
-
}): Promise<void>;
|
|
19
|
+
private log;
|
|
20
|
+
wrapRun(next: () => Promise<LLMBridge.Response>, context: LLMBridge.PluginCompletionContext): Promise<LLMBridge.Response>;
|
|
21
|
+
wrapExec(next: (params: any) => Promise<any>, params: any, context: LLMBridge.PluginCompletionContext): Promise<any>;
|
|
22
|
+
wrapToolExec(next: (tool: LLMBridge.Tool, counter: number, input: any) => Promise<any>, tool: LLMBridge.Tool, counter: number, input: any, context: LLMBridge.PluginCompletionContext): Promise<any>;
|
|
23
23
|
createLogFiles(requestId: string, type: 'request' | 'response', data: any): void;
|
|
24
24
|
createTxtFile(filePath: string, data: any): void;
|
|
25
25
|
objectToTxt(obj: any, prefix?: string): string;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
export { LoggingPlugin, type LoggingPluginOptions, generateRandomDigits };
|
|
28
|
+
export { type Logger, LoggingPlugin, type LoggingPluginOptions, generateRandomDigits };
|
package/dist/index.js
CHANGED
|
@@ -46,27 +46,36 @@ function generateRandomDigits(length) {
|
|
|
46
46
|
var LoggingPlugin = class {
|
|
47
47
|
constructor(options) {
|
|
48
48
|
this.options = options;
|
|
49
|
+
this.logger = options.logger;
|
|
49
50
|
}
|
|
50
|
-
|
|
51
|
-
|
|
51
|
+
log(message) {
|
|
52
|
+
if (!this.logger) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const logFn = this.logger.info || this.logger.log;
|
|
56
|
+
if (logFn) {
|
|
57
|
+
logFn.call(this.logger, message);
|
|
58
|
+
}
|
|
52
59
|
}
|
|
53
|
-
async
|
|
60
|
+
async wrapRun(next, context) {
|
|
61
|
+
this.log(`run ${context.model}`);
|
|
62
|
+
const response = await next();
|
|
54
63
|
const lastResponsePath = import_path.default.join(this.options.folder, "last_response.json");
|
|
55
64
|
import_fs.default.writeFileSync(lastResponsePath, JSON.stringify(response, null, 2));
|
|
65
|
+
return response;
|
|
56
66
|
}
|
|
57
|
-
async
|
|
67
|
+
async wrapExec(next, params, context) {
|
|
58
68
|
const requestId = generateRandomDigits(4);
|
|
59
69
|
this.createLogFiles(requestId, "request", params);
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
this.createLogFiles(beforeResponse, "response", response);
|
|
70
|
+
const response = await next(params);
|
|
71
|
+
this.createLogFiles(requestId, "response", response);
|
|
72
|
+
return response;
|
|
64
73
|
}
|
|
65
|
-
async
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
74
|
+
async wrapToolExec(next, tool, counter, input, context) {
|
|
75
|
+
this.log(`run (${counter + 1}/${context.options.tools?.usesLimit}) tool ${tool.name} ${JSON.stringify(input)}`);
|
|
76
|
+
const result = await next(tool, counter, input);
|
|
77
|
+
this.log(`tool response ${JSON.stringify(result)}`);
|
|
78
|
+
return result;
|
|
70
79
|
}
|
|
71
80
|
createLogFiles(requestId, type, data) {
|
|
72
81
|
const currentDate = (0, import_moment.default)();
|
package/dist/index.mjs
CHANGED
|
@@ -9,27 +9,36 @@ function generateRandomDigits(length) {
|
|
|
9
9
|
var LoggingPlugin = class {
|
|
10
10
|
constructor(options) {
|
|
11
11
|
this.options = options;
|
|
12
|
+
this.logger = options.logger;
|
|
12
13
|
}
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
log(message) {
|
|
15
|
+
if (!this.logger) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const logFn = this.logger.info || this.logger.log;
|
|
19
|
+
if (logFn) {
|
|
20
|
+
logFn.call(this.logger, message);
|
|
21
|
+
}
|
|
15
22
|
}
|
|
16
|
-
async
|
|
23
|
+
async wrapRun(next, context) {
|
|
24
|
+
this.log(`run ${context.model}`);
|
|
25
|
+
const response = await next();
|
|
17
26
|
const lastResponsePath = path.join(this.options.folder, "last_response.json");
|
|
18
27
|
fs.writeFileSync(lastResponsePath, JSON.stringify(response, null, 2));
|
|
28
|
+
return response;
|
|
19
29
|
}
|
|
20
|
-
async
|
|
30
|
+
async wrapExec(next, params, context) {
|
|
21
31
|
const requestId = generateRandomDigits(4);
|
|
22
32
|
this.createLogFiles(requestId, "request", params);
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
this.createLogFiles(beforeResponse, "response", response);
|
|
33
|
+
const response = await next(params);
|
|
34
|
+
this.createLogFiles(requestId, "response", response);
|
|
35
|
+
return response;
|
|
27
36
|
}
|
|
28
|
-
async
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
37
|
+
async wrapToolExec(next, tool, counter, input, context) {
|
|
38
|
+
this.log(`run (${counter + 1}/${context.options.tools?.usesLimit}) tool ${tool.name} ${JSON.stringify(input)}`);
|
|
39
|
+
const result = await next(tool, counter, input);
|
|
40
|
+
this.log(`tool response ${JSON.stringify(result)}`);
|
|
41
|
+
return result;
|
|
33
42
|
}
|
|
34
43
|
createLogFiles(requestId, type, data) {
|
|
35
44
|
const currentDate = moment();
|
package/package.json
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@llmbridge/plugin-logging",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Logging plugin for LLMBridge",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
8
|
"scripts": {
|
|
9
|
-
"build": "
|
|
9
|
+
"build": "npm run clean && tsup src/index.ts --format cjs,esm --dts",
|
|
10
10
|
"test": "vitest run",
|
|
11
|
-
"clean": "
|
|
11
|
+
"clean": "rimraf dist",
|
|
12
|
+
"build:publish": "npm run build && npm publish"
|
|
12
13
|
},
|
|
13
14
|
"keywords": [
|
|
14
15
|
"llm",
|
|
@@ -26,7 +27,7 @@
|
|
|
26
27
|
"moment": "^2.30.1"
|
|
27
28
|
},
|
|
28
29
|
"peerDependencies": {
|
|
29
|
-
"@llmbridge/core": ">=0.0
|
|
30
|
+
"@llmbridge/core": ">=0.1.0 <0.2.0",
|
|
30
31
|
"moment": "^2.29.0",
|
|
31
32
|
"typescript": "^5.0.0"
|
|
32
33
|
},
|
|
@@ -34,7 +35,8 @@
|
|
|
34
35
|
"@types/node": "^18.11.9",
|
|
35
36
|
"typescript": "^5.7.3",
|
|
36
37
|
"tsup": "^8.4.0",
|
|
37
|
-
"vitest": "^3.0.7"
|
|
38
|
+
"vitest": "^3.0.7",
|
|
39
|
+
"rimraf": "^5.0.5"
|
|
38
40
|
},
|
|
39
41
|
"author": "",
|
|
40
42
|
"license": "MIT"
|