@digipair/skill-logger 0.28.1 → 0.28.3
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/index.cjs.js +35 -35
- package/index.esm.js +35 -35
- package/package.json +1 -1
package/index.cjs.js
CHANGED
@@ -4,25 +4,25 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
5
5
|
var fs = require('fs');
|
6
6
|
|
7
|
-
var
|
7
|
+
var _process_env_DIGIPAIR_LOGS_PATH;
|
8
8
|
let LoggerService = class LoggerService {
|
9
|
-
async initialize(path = (
|
9
|
+
async initialize(path = (_process_env_DIGIPAIR_LOGS_PATH = process.env['DIGIPAIR_LOGS_PATH']) != null ? _process_env_DIGIPAIR_LOGS_PATH : './factory/digipairs/logs') {
|
10
10
|
// create logs directory if it doesn't exist
|
11
|
-
await fs.promises.mkdir(`${path}/
|
11
|
+
await fs.promises.mkdir(`${path}/factory`, {
|
12
12
|
recursive: true
|
13
13
|
});
|
14
14
|
// create consumption-daily directory if it doesn't exist
|
15
|
-
await fs.promises.mkdir(`${path}/
|
15
|
+
await fs.promises.mkdir(`${path}/consumption-daily`, {
|
16
16
|
recursive: true
|
17
17
|
});
|
18
18
|
// create consumption-monthly directory if it doesn't exist
|
19
|
-
await fs.promises.mkdir(`${path}/
|
19
|
+
await fs.promises.mkdir(`${path}/consumption-monthly`, {
|
20
20
|
recursive: true
|
21
21
|
});
|
22
22
|
}
|
23
23
|
async addConsumption(context, service, model, promptTokens, completionTokens) {
|
24
|
-
var
|
25
|
-
const
|
24
|
+
var _context_DIGIPAIR_LOGS_PATH, _ref;
|
25
|
+
const DIGIPAIR_LOGS_PATH = (_ref = (_context_DIGIPAIR_LOGS_PATH = context.DIGIPAIR_LOGS_PATH) != null ? _context_DIGIPAIR_LOGS_PATH : process.env['DIGIPAIR_LOGS_PATH']) != null ? _ref : './factory/digipairs/logs';
|
26
26
|
const current = new Date();
|
27
27
|
const line = {
|
28
28
|
date: current.getTime(),
|
@@ -33,12 +33,12 @@ let LoggerService = class LoggerService {
|
|
33
33
|
promptTokens,
|
34
34
|
completionTokens
|
35
35
|
};
|
36
|
-
await fs.promises.appendFile(`${
|
36
|
+
await fs.promises.appendFile(`${DIGIPAIR_LOGS_PATH}/consumption-daily/${current.toISOString().split('T')[0]}.jsonl`, '\n' + JSON.stringify(line), 'utf8');
|
37
37
|
}
|
38
38
|
async computeDailyConsumption(params, _pinsSettingsList, context) {
|
39
|
-
var
|
40
|
-
const { date, path = (_ref = (
|
41
|
-
const text = await fs.promises.readFile(`${path}/
|
39
|
+
var _context_DIGIPAIR_LOGS_PATH, _ref;
|
40
|
+
const { date, path = (_ref = (_context_DIGIPAIR_LOGS_PATH = context.DIGIPAIR_LOGS_PATH) != null ? _context_DIGIPAIR_LOGS_PATH : process.env['DIGIPAIR_LOGS_PATH']) != null ? _ref : './factory/digipairs/logs' } = params;
|
41
|
+
const text = await fs.promises.readFile(`${path}/consumption-daily/${date}.jsonl`, 'utf8');
|
42
42
|
const lines = text.split('\n').filter((line)=>line !== '');
|
43
43
|
const result = lines.map((line)=>JSON.parse(line));
|
44
44
|
const dayLines = result.reduce((acc, curr)=>{
|
@@ -57,31 +57,31 @@ let LoggerService = class LoggerService {
|
|
57
57
|
line.promptTokens += curr.promptTokens;
|
58
58
|
line.completionTokens += curr.completionTokens;
|
59
59
|
}, []);
|
60
|
-
await fs.promises.appendFile(`${path}/
|
60
|
+
await fs.promises.appendFile(`${path}/consumption-monthly/${date.substring(0, 7)}.jsonl`, '\n' + dayLines.map((line)=>JSON.stringify(line)).join('\n'), 'utf8');
|
61
61
|
}
|
62
62
|
async consumptions(params, _pinsSettingsList, context) {
|
63
|
-
var
|
64
|
-
const { date, path = (_ref = (
|
65
|
-
const text = await fs.promises.readFile(`${path}/
|
63
|
+
var _context_DIGIPAIR_LOGS_PATH, _ref;
|
64
|
+
const { date, path = (_ref = (_context_DIGIPAIR_LOGS_PATH = context.DIGIPAIR_LOGS_PATH) != null ? _context_DIGIPAIR_LOGS_PATH : process.env['DIGIPAIR_LOGS_PATH']) != null ? _ref : './factory/digipairs/logs' } = params;
|
65
|
+
const text = await fs.promises.readFile(`${path}/consumption-daily/${date}.jsonl`, 'utf8');
|
66
66
|
const lines = text.split('\n').filter((line)=>line !== '');
|
67
67
|
const result = lines.map((line)=>JSON.parse(line));
|
68
68
|
return result;
|
69
69
|
}
|
70
70
|
async dailyConsumptions(params, _pinsSettingsList, context) {
|
71
|
-
var
|
72
|
-
const { path = (_ref = (
|
73
|
-
const files = (await fs.promises.readdir(`${path}/
|
71
|
+
var _context_DIGIPAIR_LOGS_PATH, _ref;
|
72
|
+
const { path = (_ref = (_context_DIGIPAIR_LOGS_PATH = context.DIGIPAIR_LOGS_PATH) != null ? _context_DIGIPAIR_LOGS_PATH : process.env['DIGIPAIR_LOGS_PATH']) != null ? _ref : './factory/digipairs/logs' } = params;
|
73
|
+
const files = (await fs.promises.readdir(`${path}/consumption-daily`)).map((file)=>file.split('.')[0]);
|
74
74
|
return files;
|
75
75
|
}
|
76
76
|
async monthlyConsumptions(params, _pinsSettingsList, context) {
|
77
|
-
var
|
78
|
-
const { path = (_ref = (
|
79
|
-
const files = (await fs.promises.readdir(`${path}/
|
77
|
+
var _context_DIGIPAIR_LOGS_PATH, _ref;
|
78
|
+
const { path = (_ref = (_context_DIGIPAIR_LOGS_PATH = context.DIGIPAIR_LOGS_PATH) != null ? _context_DIGIPAIR_LOGS_PATH : process.env['DIGIPAIR_LOGS_PATH']) != null ? _ref : './factory/digipairs/logs' } = params;
|
79
|
+
const files = (await fs.promises.readdir(`${path}/consumption-monthly`)).map((file)=>file.split('.')[0]);
|
80
80
|
return files;
|
81
81
|
}
|
82
82
|
async addLog(context, type, message) {
|
83
|
-
var
|
84
|
-
const
|
83
|
+
var _context_DIGIPAIR_LOGS_PATH, _ref;
|
84
|
+
const DIGIPAIR_LOGS_PATH = (_ref = (_context_DIGIPAIR_LOGS_PATH = context.DIGIPAIR_LOGS_PATH) != null ? _context_DIGIPAIR_LOGS_PATH : process.env['DIGIPAIR_LOGS_PATH']) != null ? _ref : './factory/digipairs/logs';
|
85
85
|
const current = new Date();
|
86
86
|
const line = {
|
87
87
|
date: current.getTime(),
|
@@ -90,30 +90,30 @@ let LoggerService = class LoggerService {
|
|
90
90
|
type,
|
91
91
|
message
|
92
92
|
};
|
93
|
-
await fs.promises.appendFile(`${
|
93
|
+
await fs.promises.appendFile(`${DIGIPAIR_LOGS_PATH}/${current.toISOString().split('T')[0]}.jsonl`, '\n' + JSON.stringify(line), 'utf8');
|
94
94
|
}
|
95
95
|
async logs(params, _pinsSettingsList, context) {
|
96
|
-
var
|
97
|
-
const { date, path = (_ref = (
|
98
|
-
const text = await fs.promises.readFile(`${path}/
|
96
|
+
var _context_DIGIPAIR_LOGS_PATH, _ref;
|
97
|
+
const { date, path = (_ref = (_context_DIGIPAIR_LOGS_PATH = context.DIGIPAIR_LOGS_PATH) != null ? _context_DIGIPAIR_LOGS_PATH : process.env['DIGIPAIR_LOGS_PATH']) != null ? _ref : './factory/digipairs/logs' } = params;
|
98
|
+
const text = await fs.promises.readFile(`${path}/factory/${date}.jsonl`, 'utf8');
|
99
99
|
const lines = text.split('\n').filter((line)=>line !== '');
|
100
100
|
const result = lines.map((line)=>JSON.parse(line));
|
101
101
|
return result;
|
102
102
|
}
|
103
103
|
async dailyLogs(params, _pinsSettingsList, context) {
|
104
|
-
var
|
105
|
-
const { path = (_ref = (
|
106
|
-
const files = (await fs.promises.readdir(`${path}/
|
104
|
+
var _context_DIGIPAIR_LOGS_PATH, _ref;
|
105
|
+
const { path = (_ref = (_context_DIGIPAIR_LOGS_PATH = context.DIGIPAIR_LOGS_PATH) != null ? _context_DIGIPAIR_LOGS_PATH : process.env['DIGIPAIR_LOGS_PATH']) != null ? _ref : './factory/digipairs/logs' } = params;
|
106
|
+
const files = (await fs.promises.readdir(`${path}/factory`)).filter((file)=>/\.jsonl$/g.test(file)).map((file)=>file.split('.')[0]);
|
107
107
|
return files;
|
108
108
|
}
|
109
109
|
async clearOldLogs(params, _pinsSettingsList, context) {
|
110
|
-
var
|
111
|
-
const { type, to, path = (_ref = (
|
112
|
-
const files = await fs.promises.readdir(`${path}
|
110
|
+
var _context_DIGIPAIR_LOGS_PATH, _ref;
|
111
|
+
const { type, to, path = (_ref = (_context_DIGIPAIR_LOGS_PATH = context.DIGIPAIR_LOGS_PATH) != null ? _context_DIGIPAIR_LOGS_PATH : process.env['DIGIPAIR_LOGS_PATH']) != null ? _ref : './factory/digipairs/logs' } = params;
|
112
|
+
const files = await fs.promises.readdir(`${path}/${type}`);
|
113
113
|
for (const file of files){
|
114
|
-
const stats = await fs.promises.stat(`${path}/${file}`);
|
114
|
+
const stats = await fs.promises.stat(`${path}/${type}/${file}`);
|
115
115
|
if (stats.mtime.getTime() < to) {
|
116
|
-
fs.promises.unlink(`${path}/${file}`);
|
116
|
+
fs.promises.unlink(`${path}/${type}/${file}`);
|
117
117
|
}
|
118
118
|
}
|
119
119
|
}
|
package/index.esm.js
CHANGED
@@ -1,24 +1,24 @@
|
|
1
1
|
import { promises } from 'fs';
|
2
2
|
|
3
|
-
var
|
3
|
+
var _process_env_DIGIPAIR_LOGS_PATH;
|
4
4
|
let LoggerService = class LoggerService {
|
5
|
-
async initialize(path = (
|
5
|
+
async initialize(path = (_process_env_DIGIPAIR_LOGS_PATH = process.env['DIGIPAIR_LOGS_PATH']) != null ? _process_env_DIGIPAIR_LOGS_PATH : './factory/digipairs/logs') {
|
6
6
|
// create logs directory if it doesn't exist
|
7
|
-
await promises.mkdir(`${path}/
|
7
|
+
await promises.mkdir(`${path}/factory`, {
|
8
8
|
recursive: true
|
9
9
|
});
|
10
10
|
// create consumption-daily directory if it doesn't exist
|
11
|
-
await promises.mkdir(`${path}/
|
11
|
+
await promises.mkdir(`${path}/consumption-daily`, {
|
12
12
|
recursive: true
|
13
13
|
});
|
14
14
|
// create consumption-monthly directory if it doesn't exist
|
15
|
-
await promises.mkdir(`${path}/
|
15
|
+
await promises.mkdir(`${path}/consumption-monthly`, {
|
16
16
|
recursive: true
|
17
17
|
});
|
18
18
|
}
|
19
19
|
async addConsumption(context, service, model, promptTokens, completionTokens) {
|
20
|
-
var
|
21
|
-
const
|
20
|
+
var _context_DIGIPAIR_LOGS_PATH, _ref;
|
21
|
+
const DIGIPAIR_LOGS_PATH = (_ref = (_context_DIGIPAIR_LOGS_PATH = context.DIGIPAIR_LOGS_PATH) != null ? _context_DIGIPAIR_LOGS_PATH : process.env['DIGIPAIR_LOGS_PATH']) != null ? _ref : './factory/digipairs/logs';
|
22
22
|
const current = new Date();
|
23
23
|
const line = {
|
24
24
|
date: current.getTime(),
|
@@ -29,12 +29,12 @@ let LoggerService = class LoggerService {
|
|
29
29
|
promptTokens,
|
30
30
|
completionTokens
|
31
31
|
};
|
32
|
-
await promises.appendFile(`${
|
32
|
+
await promises.appendFile(`${DIGIPAIR_LOGS_PATH}/consumption-daily/${current.toISOString().split('T')[0]}.jsonl`, '\n' + JSON.stringify(line), 'utf8');
|
33
33
|
}
|
34
34
|
async computeDailyConsumption(params, _pinsSettingsList, context) {
|
35
|
-
var
|
36
|
-
const { date, path = (_ref = (
|
37
|
-
const text = await promises.readFile(`${path}/
|
35
|
+
var _context_DIGIPAIR_LOGS_PATH, _ref;
|
36
|
+
const { date, path = (_ref = (_context_DIGIPAIR_LOGS_PATH = context.DIGIPAIR_LOGS_PATH) != null ? _context_DIGIPAIR_LOGS_PATH : process.env['DIGIPAIR_LOGS_PATH']) != null ? _ref : './factory/digipairs/logs' } = params;
|
37
|
+
const text = await promises.readFile(`${path}/consumption-daily/${date}.jsonl`, 'utf8');
|
38
38
|
const lines = text.split('\n').filter((line)=>line !== '');
|
39
39
|
const result = lines.map((line)=>JSON.parse(line));
|
40
40
|
const dayLines = result.reduce((acc, curr)=>{
|
@@ -53,31 +53,31 @@ let LoggerService = class LoggerService {
|
|
53
53
|
line.promptTokens += curr.promptTokens;
|
54
54
|
line.completionTokens += curr.completionTokens;
|
55
55
|
}, []);
|
56
|
-
await promises.appendFile(`${path}/
|
56
|
+
await promises.appendFile(`${path}/consumption-monthly/${date.substring(0, 7)}.jsonl`, '\n' + dayLines.map((line)=>JSON.stringify(line)).join('\n'), 'utf8');
|
57
57
|
}
|
58
58
|
async consumptions(params, _pinsSettingsList, context) {
|
59
|
-
var
|
60
|
-
const { date, path = (_ref = (
|
61
|
-
const text = await promises.readFile(`${path}/
|
59
|
+
var _context_DIGIPAIR_LOGS_PATH, _ref;
|
60
|
+
const { date, path = (_ref = (_context_DIGIPAIR_LOGS_PATH = context.DIGIPAIR_LOGS_PATH) != null ? _context_DIGIPAIR_LOGS_PATH : process.env['DIGIPAIR_LOGS_PATH']) != null ? _ref : './factory/digipairs/logs' } = params;
|
61
|
+
const text = await promises.readFile(`${path}/consumption-daily/${date}.jsonl`, 'utf8');
|
62
62
|
const lines = text.split('\n').filter((line)=>line !== '');
|
63
63
|
const result = lines.map((line)=>JSON.parse(line));
|
64
64
|
return result;
|
65
65
|
}
|
66
66
|
async dailyConsumptions(params, _pinsSettingsList, context) {
|
67
|
-
var
|
68
|
-
const { path = (_ref = (
|
69
|
-
const files = (await promises.readdir(`${path}/
|
67
|
+
var _context_DIGIPAIR_LOGS_PATH, _ref;
|
68
|
+
const { path = (_ref = (_context_DIGIPAIR_LOGS_PATH = context.DIGIPAIR_LOGS_PATH) != null ? _context_DIGIPAIR_LOGS_PATH : process.env['DIGIPAIR_LOGS_PATH']) != null ? _ref : './factory/digipairs/logs' } = params;
|
69
|
+
const files = (await promises.readdir(`${path}/consumption-daily`)).map((file)=>file.split('.')[0]);
|
70
70
|
return files;
|
71
71
|
}
|
72
72
|
async monthlyConsumptions(params, _pinsSettingsList, context) {
|
73
|
-
var
|
74
|
-
const { path = (_ref = (
|
75
|
-
const files = (await promises.readdir(`${path}/
|
73
|
+
var _context_DIGIPAIR_LOGS_PATH, _ref;
|
74
|
+
const { path = (_ref = (_context_DIGIPAIR_LOGS_PATH = context.DIGIPAIR_LOGS_PATH) != null ? _context_DIGIPAIR_LOGS_PATH : process.env['DIGIPAIR_LOGS_PATH']) != null ? _ref : './factory/digipairs/logs' } = params;
|
75
|
+
const files = (await promises.readdir(`${path}/consumption-monthly`)).map((file)=>file.split('.')[0]);
|
76
76
|
return files;
|
77
77
|
}
|
78
78
|
async addLog(context, type, message) {
|
79
|
-
var
|
80
|
-
const
|
79
|
+
var _context_DIGIPAIR_LOGS_PATH, _ref;
|
80
|
+
const DIGIPAIR_LOGS_PATH = (_ref = (_context_DIGIPAIR_LOGS_PATH = context.DIGIPAIR_LOGS_PATH) != null ? _context_DIGIPAIR_LOGS_PATH : process.env['DIGIPAIR_LOGS_PATH']) != null ? _ref : './factory/digipairs/logs';
|
81
81
|
const current = new Date();
|
82
82
|
const line = {
|
83
83
|
date: current.getTime(),
|
@@ -86,30 +86,30 @@ let LoggerService = class LoggerService {
|
|
86
86
|
type,
|
87
87
|
message
|
88
88
|
};
|
89
|
-
await promises.appendFile(`${
|
89
|
+
await promises.appendFile(`${DIGIPAIR_LOGS_PATH}/${current.toISOString().split('T')[0]}.jsonl`, '\n' + JSON.stringify(line), 'utf8');
|
90
90
|
}
|
91
91
|
async logs(params, _pinsSettingsList, context) {
|
92
|
-
var
|
93
|
-
const { date, path = (_ref = (
|
94
|
-
const text = await promises.readFile(`${path}/
|
92
|
+
var _context_DIGIPAIR_LOGS_PATH, _ref;
|
93
|
+
const { date, path = (_ref = (_context_DIGIPAIR_LOGS_PATH = context.DIGIPAIR_LOGS_PATH) != null ? _context_DIGIPAIR_LOGS_PATH : process.env['DIGIPAIR_LOGS_PATH']) != null ? _ref : './factory/digipairs/logs' } = params;
|
94
|
+
const text = await promises.readFile(`${path}/factory/${date}.jsonl`, 'utf8');
|
95
95
|
const lines = text.split('\n').filter((line)=>line !== '');
|
96
96
|
const result = lines.map((line)=>JSON.parse(line));
|
97
97
|
return result;
|
98
98
|
}
|
99
99
|
async dailyLogs(params, _pinsSettingsList, context) {
|
100
|
-
var
|
101
|
-
const { path = (_ref = (
|
102
|
-
const files = (await promises.readdir(`${path}/
|
100
|
+
var _context_DIGIPAIR_LOGS_PATH, _ref;
|
101
|
+
const { path = (_ref = (_context_DIGIPAIR_LOGS_PATH = context.DIGIPAIR_LOGS_PATH) != null ? _context_DIGIPAIR_LOGS_PATH : process.env['DIGIPAIR_LOGS_PATH']) != null ? _ref : './factory/digipairs/logs' } = params;
|
102
|
+
const files = (await promises.readdir(`${path}/factory`)).filter((file)=>/\.jsonl$/g.test(file)).map((file)=>file.split('.')[0]);
|
103
103
|
return files;
|
104
104
|
}
|
105
105
|
async clearOldLogs(params, _pinsSettingsList, context) {
|
106
|
-
var
|
107
|
-
const { type, to, path = (_ref = (
|
108
|
-
const files = await promises.readdir(`${path}
|
106
|
+
var _context_DIGIPAIR_LOGS_PATH, _ref;
|
107
|
+
const { type, to, path = (_ref = (_context_DIGIPAIR_LOGS_PATH = context.DIGIPAIR_LOGS_PATH) != null ? _context_DIGIPAIR_LOGS_PATH : process.env['DIGIPAIR_LOGS_PATH']) != null ? _ref : './factory/digipairs/logs' } = params;
|
108
|
+
const files = await promises.readdir(`${path}/${type}`);
|
109
109
|
for (const file of files){
|
110
|
-
const stats = await promises.stat(`${path}/${file}`);
|
110
|
+
const stats = await promises.stat(`${path}/${type}/${file}`);
|
111
111
|
if (stats.mtime.getTime() < to) {
|
112
|
-
promises.unlink(`${path}/${file}`);
|
112
|
+
promises.unlink(`${path}/${type}/${file}`);
|
113
113
|
}
|
114
114
|
}
|
115
115
|
}
|