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