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