@llmbridge/plugin-logging 0.1.3 → 0.1.4

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.js CHANGED
@@ -67,7 +67,7 @@ var LoggingPlugin = class {
67
67
  model: context.model,
68
68
  turns: []
69
69
  };
70
- this.runSessions.set(context, session);
70
+ this.runSessions.set(context.options, session);
71
71
  try {
72
72
  const response = await next();
73
73
  const lastResponsePath = import_node_path.default.join(this.options.folder, "last_response.json");
@@ -78,21 +78,22 @@ var LoggingPlugin = class {
78
78
  this.writeSessionXml(session);
79
79
  throw error;
80
80
  } finally {
81
- this.runSessions.delete(context);
81
+ this.runSessions.delete(context.options);
82
82
  }
83
83
  }
84
84
  async wrapExec(next, params, context) {
85
- const requestId = generateRandomDigits(4);
86
- const requestTime = (0, import_moment.default)();
87
- const session = this.runSessions.get(context);
85
+ const session = this.runSessions.get(context.options);
88
86
  const turn = { request: params, response: void 0, toolExecutions: [] };
89
- this.writeJsonLog(requestTime, requestId, "request", params);
87
+ const logTime = session ? session.startTime : (0, import_moment.default)();
88
+ const turnNumber = session ? session.turns.length + 1 : 0;
89
+ const logId = session ? `${session.requestId}.t${turnNumber}` : generateRandomDigits(4);
90
+ this.writeJsonLog(logTime, logId, "request", params);
90
91
  if (session) {
91
92
  session.turns.push(turn);
92
93
  this.writeSessionXml(session);
93
94
  }
94
95
  const response = await next(params);
95
- this.writeJsonLog((0, import_moment.default)(), requestId, "response", response);
96
+ this.writeJsonLog(logTime, logId, "response", response);
96
97
  if (session) {
97
98
  turn.response = response;
98
99
  this.writeSessionXml(session);
@@ -103,7 +104,7 @@ var LoggingPlugin = class {
103
104
  this.log(`run (${counter + 1}/${context.options.tools?.usesLimit}) tool ${tool.name} ${JSON.stringify(input)}`);
104
105
  const result = await next(tool, counter, input);
105
106
  this.log(`tool response ${JSON.stringify(result)}`);
106
- const session = this.runSessions.get(context);
107
+ const session = this.runSessions.get(context.options);
107
108
  if (session && session.turns.length > 0) {
108
109
  const lastTurn = session.turns[session.turns.length - 1];
109
110
  lastTurn.toolExecutions.push({ toolName: tool.name, counter, input, result });
package/dist/index.mjs CHANGED
@@ -30,7 +30,7 @@ var LoggingPlugin = class {
30
30
  model: context.model,
31
31
  turns: []
32
32
  };
33
- this.runSessions.set(context, session);
33
+ this.runSessions.set(context.options, session);
34
34
  try {
35
35
  const response = await next();
36
36
  const lastResponsePath = path.join(this.options.folder, "last_response.json");
@@ -41,21 +41,22 @@ var LoggingPlugin = class {
41
41
  this.writeSessionXml(session);
42
42
  throw error;
43
43
  } finally {
44
- this.runSessions.delete(context);
44
+ this.runSessions.delete(context.options);
45
45
  }
46
46
  }
47
47
  async wrapExec(next, params, context) {
48
- const requestId = generateRandomDigits(4);
49
- const requestTime = moment();
50
- const session = this.runSessions.get(context);
48
+ const session = this.runSessions.get(context.options);
51
49
  const turn = { request: params, response: void 0, toolExecutions: [] };
52
- this.writeJsonLog(requestTime, requestId, "request", params);
50
+ const logTime = session ? session.startTime : moment();
51
+ const turnNumber = session ? session.turns.length + 1 : 0;
52
+ const logId = session ? `${session.requestId}.t${turnNumber}` : generateRandomDigits(4);
53
+ this.writeJsonLog(logTime, logId, "request", params);
53
54
  if (session) {
54
55
  session.turns.push(turn);
55
56
  this.writeSessionXml(session);
56
57
  }
57
58
  const response = await next(params);
58
- this.writeJsonLog(moment(), requestId, "response", response);
59
+ this.writeJsonLog(logTime, logId, "response", response);
59
60
  if (session) {
60
61
  turn.response = response;
61
62
  this.writeSessionXml(session);
@@ -66,7 +67,7 @@ var LoggingPlugin = class {
66
67
  this.log(`run (${counter + 1}/${context.options.tools?.usesLimit}) tool ${tool.name} ${JSON.stringify(input)}`);
67
68
  const result = await next(tool, counter, input);
68
69
  this.log(`tool response ${JSON.stringify(result)}`);
69
- const session = this.runSessions.get(context);
70
+ const session = this.runSessions.get(context.options);
70
71
  if (session && session.turns.length > 0) {
71
72
  const lastTurn = session.turns[session.turns.length - 1];
72
73
  lastTurn.toolExecutions.push({ toolName: tool.name, counter, input, result });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@llmbridge/plugin-logging",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "Logging plugin for LLMBridge",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",