@llmbridge/plugin-logging 0.1.0 → 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 CHANGED
@@ -1,12 +1,22 @@
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);
19
+ private log;
10
20
  wrapRun(next: () => Promise<LLMBridge.Response>, context: LLMBridge.PluginCompletionContext): Promise<LLMBridge.Response>;
11
21
  wrapExec(next: (params: any) => Promise<any>, params: any, context: LLMBridge.PluginCompletionContext): Promise<any>;
12
22
  wrapToolExec(next: (tool: LLMBridge.Tool, counter: number, input: any) => Promise<any>, tool: LLMBridge.Tool, counter: number, input: any, context: LLMBridge.PluginCompletionContext): Promise<any>;
@@ -15,4 +25,4 @@ declare class LoggingPlugin implements LLMBridge.Plugin<void, string, void, void
15
25
  objectToTxt(obj: any, prefix?: string): string;
16
26
  }
17
27
 
18
- export { LoggingPlugin, type LoggingPluginOptions, generateRandomDigits };
28
+ export { type Logger, LoggingPlugin, type LoggingPluginOptions, generateRandomDigits };
package/dist/index.d.ts CHANGED
@@ -1,12 +1,22 @@
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);
19
+ private log;
10
20
  wrapRun(next: () => Promise<LLMBridge.Response>, context: LLMBridge.PluginCompletionContext): Promise<LLMBridge.Response>;
11
21
  wrapExec(next: (params: any) => Promise<any>, params: any, context: LLMBridge.PluginCompletionContext): Promise<any>;
12
22
  wrapToolExec(next: (tool: LLMBridge.Tool, counter: number, input: any) => Promise<any>, tool: LLMBridge.Tool, counter: number, input: any, context: LLMBridge.PluginCompletionContext): Promise<any>;
@@ -15,4 +25,4 @@ declare class LoggingPlugin implements LLMBridge.Plugin<void, string, void, void
15
25
  objectToTxt(obj: any, prefix?: string): string;
16
26
  }
17
27
 
18
- export { LoggingPlugin, type LoggingPluginOptions, generateRandomDigits };
28
+ export { type Logger, LoggingPlugin, type LoggingPluginOptions, generateRandomDigits };
package/dist/index.js CHANGED
@@ -46,9 +46,19 @@ function generateRandomDigits(length) {
46
46
  var LoggingPlugin = class {
47
47
  constructor(options) {
48
48
  this.options = options;
49
+ this.logger = options.logger;
50
+ }
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
+ }
49
59
  }
50
60
  async wrapRun(next, context) {
51
- console.log("run", context.model);
61
+ this.log(`run ${context.model}`);
52
62
  const response = await next();
53
63
  const lastResponsePath = import_path.default.join(this.options.folder, "last_response.json");
54
64
  import_fs.default.writeFileSync(lastResponsePath, JSON.stringify(response, null, 2));
@@ -62,9 +72,9 @@ var LoggingPlugin = class {
62
72
  return response;
63
73
  }
64
74
  async wrapToolExec(next, tool, counter, input, context) {
65
- console.log(`run (${counter + 1}/${context.options.tools?.usesLimit}) tool ${tool.name}`, input);
75
+ this.log(`run (${counter + 1}/${context.options.tools?.usesLimit}) tool ${tool.name} ${JSON.stringify(input)}`);
66
76
  const result = await next(tool, counter, input);
67
- console.log(`tool response`, result);
77
+ this.log(`tool response ${JSON.stringify(result)}`);
68
78
  return result;
69
79
  }
70
80
  createLogFiles(requestId, type, data) {
package/dist/index.mjs CHANGED
@@ -9,9 +9,19 @@ function generateRandomDigits(length) {
9
9
  var LoggingPlugin = class {
10
10
  constructor(options) {
11
11
  this.options = options;
12
+ this.logger = options.logger;
13
+ }
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
+ }
12
22
  }
13
23
  async wrapRun(next, context) {
14
- console.log("run", context.model);
24
+ this.log(`run ${context.model}`);
15
25
  const response = await next();
16
26
  const lastResponsePath = path.join(this.options.folder, "last_response.json");
17
27
  fs.writeFileSync(lastResponsePath, JSON.stringify(response, null, 2));
@@ -25,9 +35,9 @@ var LoggingPlugin = class {
25
35
  return response;
26
36
  }
27
37
  async wrapToolExec(next, tool, counter, input, context) {
28
- console.log(`run (${counter + 1}/${context.options.tools?.usesLimit}) tool ${tool.name}`, input);
38
+ this.log(`run (${counter + 1}/${context.options.tools?.usesLimit}) tool ${tool.name} ${JSON.stringify(input)}`);
29
39
  const result = await next(tool, counter, input);
30
- console.log(`tool response`, result);
40
+ this.log(`tool response ${JSON.stringify(result)}`);
31
41
  return result;
32
42
  }
33
43
  createLogFiles(requestId, type, data) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@llmbridge/plugin-logging",
3
- "version": "0.1.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",