@llmbridge/plugin-logging 0.0.3 → 0.1.0

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 CHANGED
@@ -7,19 +7,9 @@ declare function generateRandomDigits(length: number): string;
7
7
  declare class LoggingPlugin implements LLMBridge.Plugin<void, string, void, void> {
8
8
  private options;
9
9
  constructor(options: LoggingPluginOptions);
10
- beforeRun(context: LLMBridge.PluginCompletionContext): Promise<void>;
11
- afterRun({ response }: {
12
- response: any;
13
- }): Promise<void>;
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>;
10
+ wrapRun(next: () => Promise<LLMBridge.Response>, context: LLMBridge.PluginCompletionContext): Promise<LLMBridge.Response>;
11
+ wrapExec(next: (params: any) => Promise<any>, params: any, context: LLMBridge.PluginCompletionContext): Promise<any>;
12
+ wrapToolExec(next: (tool: LLMBridge.Tool, counter: number, input: any) => Promise<any>, tool: LLMBridge.Tool, counter: number, input: any, context: LLMBridge.PluginCompletionContext): Promise<any>;
23
13
  createLogFiles(requestId: string, type: 'request' | 'response', data: any): void;
24
14
  createTxtFile(filePath: string, data: any): void;
25
15
  objectToTxt(obj: any, prefix?: string): string;
package/dist/index.d.ts CHANGED
@@ -7,19 +7,9 @@ declare function generateRandomDigits(length: number): string;
7
7
  declare class LoggingPlugin implements LLMBridge.Plugin<void, string, void, void> {
8
8
  private options;
9
9
  constructor(options: LoggingPluginOptions);
10
- beforeRun(context: LLMBridge.PluginCompletionContext): Promise<void>;
11
- afterRun({ response }: {
12
- response: any;
13
- }): Promise<void>;
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>;
10
+ wrapRun(next: () => Promise<LLMBridge.Response>, context: LLMBridge.PluginCompletionContext): Promise<LLMBridge.Response>;
11
+ wrapExec(next: (params: any) => Promise<any>, params: any, context: LLMBridge.PluginCompletionContext): Promise<any>;
12
+ wrapToolExec(next: (tool: LLMBridge.Tool, counter: number, input: any) => Promise<any>, tool: LLMBridge.Tool, counter: number, input: any, context: LLMBridge.PluginCompletionContext): Promise<any>;
23
13
  createLogFiles(requestId: string, type: 'request' | 'response', data: any): void;
24
14
  createTxtFile(filePath: string, data: any): void;
25
15
  objectToTxt(obj: any, prefix?: string): string;
package/dist/index.js CHANGED
@@ -47,26 +47,25 @@ var LoggingPlugin = class {
47
47
  constructor(options) {
48
48
  this.options = options;
49
49
  }
50
- async beforeRun(context) {
50
+ async wrapRun(next, context) {
51
51
  console.log("run", context.model);
52
- }
53
- async afterRun({ response }) {
52
+ const response = await next();
54
53
  const lastResponsePath = import_path.default.join(this.options.folder, "last_response.json");
55
54
  import_fs.default.writeFileSync(lastResponsePath, JSON.stringify(response, null, 2));
55
+ return response;
56
56
  }
57
- async beforeExec(params) {
57
+ async wrapExec(next, params, context) {
58
58
  const requestId = generateRandomDigits(4);
59
59
  this.createLogFiles(requestId, "request", params);
60
- return requestId;
61
- }
62
- async afterExec({ beforeResponse, response }) {
63
- this.createLogFiles(beforeResponse, "response", response);
60
+ const response = await next(params);
61
+ this.createLogFiles(requestId, "response", response);
62
+ return response;
64
63
  }
65
- async beforeToolExec(tool, counter, input, context) {
64
+ async wrapToolExec(next, tool, counter, input, context) {
66
65
  console.log(`run (${counter + 1}/${context.options.tools?.usesLimit}) tool ${tool.name}`, input);
67
- }
68
- async afterToolExec({ response }) {
69
- console.log(`tool response`, response);
66
+ const result = await next(tool, counter, input);
67
+ console.log(`tool response`, result);
68
+ return result;
70
69
  }
71
70
  createLogFiles(requestId, type, data) {
72
71
  const currentDate = (0, import_moment.default)();
package/dist/index.mjs CHANGED
@@ -10,26 +10,25 @@ var LoggingPlugin = class {
10
10
  constructor(options) {
11
11
  this.options = options;
12
12
  }
13
- async beforeRun(context) {
13
+ async wrapRun(next, context) {
14
14
  console.log("run", context.model);
15
- }
16
- async afterRun({ response }) {
15
+ const response = await next();
17
16
  const lastResponsePath = path.join(this.options.folder, "last_response.json");
18
17
  fs.writeFileSync(lastResponsePath, JSON.stringify(response, null, 2));
18
+ return response;
19
19
  }
20
- async beforeExec(params) {
20
+ async wrapExec(next, params, context) {
21
21
  const requestId = generateRandomDigits(4);
22
22
  this.createLogFiles(requestId, "request", params);
23
- return requestId;
24
- }
25
- async afterExec({ beforeResponse, response }) {
26
- this.createLogFiles(beforeResponse, "response", response);
23
+ const response = await next(params);
24
+ this.createLogFiles(requestId, "response", response);
25
+ return response;
27
26
  }
28
- async beforeToolExec(tool, counter, input, context) {
27
+ async wrapToolExec(next, tool, counter, input, context) {
29
28
  console.log(`run (${counter + 1}/${context.options.tools?.usesLimit}) tool ${tool.name}`, input);
30
- }
31
- async afterToolExec({ response }) {
32
- console.log(`tool response`, response);
29
+ const result = await next(tool, counter, input);
30
+ console.log(`tool response`, result);
31
+ return result;
33
32
  }
34
33
  createLogFiles(requestId, type, data) {
35
34
  const currentDate = moment();
package/package.json CHANGED
@@ -1,14 +1,15 @@
1
1
  {
2
2
  "name": "@llmbridge/plugin-logging",
3
- "version": "0.0.3",
3
+ "version": "0.1.0",
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": "pnpm clean && tsup src/index.ts --format cjs,esm --dts",
9
+ "build": "npm run clean && tsup src/index.ts --format cjs,esm --dts",
10
10
  "test": "vitest run",
11
- "clean": "rm -rf dist"
11
+ "clean": "rimraf dist",
12
+ "build:publish": "npm run build && npm publish"
12
13
  },
13
14
  "keywords": [
14
15
  "llm",
@@ -23,16 +24,19 @@
23
24
  "access": "public"
24
25
  },
25
26
  "dependencies": {
27
+ "moment": "^2.30.1"
26
28
  },
27
29
  "peerDependencies": {
28
- "@llmbridge/core": "^0.0.3",
29
- "moment": "^2.29.0"
30
+ "@llmbridge/core": ">=0.1.0 <0.2.0",
31
+ "moment": "^2.29.0",
32
+ "typescript": "^5.0.0"
30
33
  },
31
34
  "devDependencies": {
32
35
  "@types/node": "^18.11.9",
33
36
  "typescript": "^5.7.3",
34
37
  "tsup": "^8.4.0",
35
- "vitest": "^3.0.7"
38
+ "vitest": "^3.0.7",
39
+ "rimraf": "^5.0.5"
36
40
  },
37
41
  "author": "",
38
42
  "license": "MIT"