@digipair/skill-logger 0.91.0-0 → 0.92.0
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.d.ts +1 -0
- package/index.cjs.js +8275 -0
- package/index.esm.js +8265 -0
- package/libs/engine/src/index.d.ts +2 -0
- package/libs/engine/src/lib/alias.interface.d.ts +9 -0
- package/libs/engine/src/lib/engine.d.ts +13 -0
- package/libs/engine/src/lib/pins-settings.interface.d.ts +15 -0
- package/libs/skill-logger/src/lib/skill-logger.d.ts +8 -0
- package/package.json +7 -23
- package/.swcrc +0 -28
- package/README.md +0 -7
- package/eslint.config.mjs +0 -22
- package/rollup.config.cjs +0 -28
- package/src/handlebars.d.ts +0 -1
- package/src/lib/skill-logger.spec.ts +0 -7
- package/src/lib/skill-logger.ts +0 -201
- package/tsconfig.json +0 -13
- package/tsconfig.lib.json +0 -19
- /package/{src/index.d.ts → index.d.ts} +0 -0
- /package/{src/index.ts → libs/skill-logger/src/index.d.ts} +0 -0
- /package/{src/schema.fr.json → schema.fr.json} +0 -0
- /package/{src/schema.json → schema.json} +0 -0
@@ -0,0 +1,13 @@
|
|
1
|
+
import { PinsSettings } from './pins-settings.interface';
|
2
|
+
type CONFIG_KEY = 'BASE_URL' | 'LIBRARIES' | 'ALIAS' | 'LOGGER';
|
3
|
+
export declare const config: {
|
4
|
+
set: (key: CONFIG_KEY, value: any) => void;
|
5
|
+
log: (level: string, path: string, message: string, context: any, data?: any) => any;
|
6
|
+
};
|
7
|
+
export declare const applyTemplate: (value: any, context: any) => any;
|
8
|
+
export declare const executePinsList: (pinsSettingsList: PinsSettings[], context: any, path?: string) => Promise<any>;
|
9
|
+
export declare const generateElementFromPins: (pinsSettings: PinsSettings, parent: Element, context: any, document?: Document, options?: {
|
10
|
+
import: boolean;
|
11
|
+
}) => Promise<Element | void>;
|
12
|
+
export declare const preparePinsSettings: (settings: PinsSettings, context: any) => PinsSettings;
|
13
|
+
export {};
|
@@ -0,0 +1,15 @@
|
|
1
|
+
export interface PinsSettings {
|
2
|
+
library: string;
|
3
|
+
element: string;
|
4
|
+
properties?: {
|
5
|
+
[key: string]: any;
|
6
|
+
};
|
7
|
+
conditions?: {
|
8
|
+
if?: boolean;
|
9
|
+
each?: any[];
|
10
|
+
};
|
11
|
+
pins?: PinsSettings[];
|
12
|
+
events?: {
|
13
|
+
[key: string]: PinsSettings[];
|
14
|
+
};
|
15
|
+
}
|
@@ -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>;
|
package/package.json
CHANGED
@@ -1,28 +1,12 @@
|
|
1
1
|
{
|
2
2
|
"name": "@digipair/skill-logger",
|
3
|
-
"version": "0.
|
4
|
-
"type": "module",
|
5
|
-
"main": "dist/libs/skill-logger/index.cjs.js",
|
6
|
-
"module": "dist/libs/skill-logger/index.esm.js",
|
7
|
-
"types": "dist/libs/skill-logger/index.esm.d.ts",
|
8
|
-
"exports": {
|
9
|
-
"./package.json": "./libs/skill-logger/package.json",
|
10
|
-
".": {
|
11
|
-
"development": "./dist/libs/skill-logger/src/index.ts",
|
12
|
-
"types": "./dist/libs/skill-logger/index.esm.d.ts",
|
13
|
-
"import": "./dist/libs/skill-logger/index.esm.js",
|
14
|
-
"default": "./dist/libs/skill-logger/index.cjs.js"
|
15
|
-
}
|
16
|
-
},
|
3
|
+
"version": "0.92.0",
|
17
4
|
"keywords": [
|
18
5
|
"digipair",
|
19
|
-
"
|
20
|
-
"
|
6
|
+
"service",
|
7
|
+
"util"
|
21
8
|
],
|
22
|
-
"
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
"@digipair/engine": "0.91.0-0"
|
27
|
-
}
|
28
|
-
}
|
9
|
+
"dependencies": {},
|
10
|
+
"main": "./index.cjs.js",
|
11
|
+
"module": "./index.esm.js"
|
12
|
+
}
|
package/.swcrc
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"jsc": {
|
3
|
-
"target": "es2017",
|
4
|
-
"parser": {
|
5
|
-
"syntax": "typescript",
|
6
|
-
"decorators": true,
|
7
|
-
"dynamicImport": true
|
8
|
-
},
|
9
|
-
"transform": {
|
10
|
-
"decoratorMetadata": true,
|
11
|
-
"legacyDecorator": true
|
12
|
-
},
|
13
|
-
"keepClassNames": true,
|
14
|
-
"externalHelpers": true,
|
15
|
-
"loose": true
|
16
|
-
},
|
17
|
-
"module": {
|
18
|
-
"type": "es6"
|
19
|
-
},
|
20
|
-
"sourceMaps": true,
|
21
|
-
"exclude": [
|
22
|
-
"jest.config.ts",
|
23
|
-
".*\\.spec.tsx?$",
|
24
|
-
".*\\.test.tsx?$",
|
25
|
-
"./src/jest-setup.ts$",
|
26
|
-
"./**/jest-setup.ts$"
|
27
|
-
]
|
28
|
-
}
|
package/README.md
DELETED
package/eslint.config.mjs
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
import baseConfig from '../../eslint.config.mjs';
|
2
|
-
|
3
|
-
export default [
|
4
|
-
...baseConfig,
|
5
|
-
{
|
6
|
-
files: ['**/*.json'],
|
7
|
-
rules: {
|
8
|
-
'@nx/dependency-checks': [
|
9
|
-
'error',
|
10
|
-
{
|
11
|
-
ignoredFiles: [
|
12
|
-
'{projectRoot}/eslint.config.{js,cjs,mjs}',
|
13
|
-
'{projectRoot}/rollup.config.{js,ts,mjs,mts,cjs,cts}',
|
14
|
-
],
|
15
|
-
},
|
16
|
-
],
|
17
|
-
},
|
18
|
-
languageOptions: {
|
19
|
-
parser: await import('jsonc-eslint-parser'),
|
20
|
-
},
|
21
|
-
},
|
22
|
-
];
|
package/rollup.config.cjs
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
const { withNx } = require('@nx/rollup/with-nx');
|
2
|
-
|
3
|
-
module.exports = withNx(
|
4
|
-
{
|
5
|
-
main: 'libs/skill-logger/src/index.ts',
|
6
|
-
outputPath: 'dist/libs/skill-logger',
|
7
|
-
tsConfig: 'libs/skill-logger/tsconfig.lib.json',
|
8
|
-
compiler: 'swc',
|
9
|
-
format: ['esm', "cjs"],
|
10
|
-
assets: [
|
11
|
-
{
|
12
|
-
input: 'libs/skill-logger/',
|
13
|
-
glob: 'package.json',
|
14
|
-
output: '.'
|
15
|
-
},
|
16
|
-
{
|
17
|
-
input: 'libs/skill-logger/src/',
|
18
|
-
glob: '*.json',
|
19
|
-
output: '.'
|
20
|
-
}
|
21
|
-
]
|
22
|
-
},
|
23
|
-
{
|
24
|
-
// Provide additional rollup configuration here. See: https://rollupjs.org/configuration-options
|
25
|
-
// e.g.
|
26
|
-
// output: { sourcemap: true },
|
27
|
-
}
|
28
|
-
);
|
package/src/handlebars.d.ts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
declare module 'handlebars/dist/handlebars.min.js';
|
package/src/lib/skill-logger.ts
DELETED
@@ -1,201 +0,0 @@
|
|
1
|
-
import { PinsSettings, config } from '@digipair/engine';
|
2
|
-
import { promises } from 'fs';
|
3
|
-
|
4
|
-
class LoggerService {
|
5
|
-
async initialize(path = process.env['DIGIPAIR_LOGS_PATH'] ?? './factory/logs') {
|
6
|
-
// create logs directory if it doesn't exist
|
7
|
-
await promises.mkdir(`${path}/factory`, { recursive: true });
|
8
|
-
|
9
|
-
// create consumption-daily directory if it doesn't exist
|
10
|
-
await promises.mkdir(`${path}/consumption-daily`, { recursive: true });
|
11
|
-
|
12
|
-
// create consumption-monthly directory if it doesn't exist
|
13
|
-
await promises.mkdir(`${path}/consumption-monthly`, { recursive: true });
|
14
|
-
}
|
15
|
-
|
16
|
-
async addLog(context: any, type: string, message: string, data?: any) {
|
17
|
-
const DIGIPAIR_LOGS_PATH =
|
18
|
-
context.privates.DIGIPAIR_LOGS_PATH ?? process.env['DIGIPAIR_LOGS_PATH'] ?? './factory/logs';
|
19
|
-
const current = new Date();
|
20
|
-
const line = {
|
21
|
-
date: current.getTime(),
|
22
|
-
digipair: context.request.digipair,
|
23
|
-
reasoning: context.request.reasoning,
|
24
|
-
type,
|
25
|
-
message,
|
26
|
-
};
|
27
|
-
|
28
|
-
config.log(type, context.__PATH__, message, context, data);
|
29
|
-
|
30
|
-
await promises.appendFile(
|
31
|
-
`${DIGIPAIR_LOGS_PATH}/factory/${current.toISOString().split('T')[0]}.jsonl`,
|
32
|
-
'\n' + JSON.stringify(line),
|
33
|
-
'utf8',
|
34
|
-
);
|
35
|
-
}
|
36
|
-
|
37
|
-
async addConsumption(
|
38
|
-
context: any,
|
39
|
-
service: string,
|
40
|
-
model: string,
|
41
|
-
promptTokens: number,
|
42
|
-
completionTokens: number,
|
43
|
-
) {
|
44
|
-
const DIGIPAIR_LOGS_PATH =
|
45
|
-
context.privates.DIGIPAIR_LOGS_PATH ?? process.env['DIGIPAIR_LOGS_PATH'] ?? './factory/logs';
|
46
|
-
const current = new Date();
|
47
|
-
const line = {
|
48
|
-
date: current.getTime(),
|
49
|
-
digipair: context.request.digipair,
|
50
|
-
reasoning: context.request.reasoning,
|
51
|
-
service,
|
52
|
-
model,
|
53
|
-
promptTokens,
|
54
|
-
completionTokens,
|
55
|
-
};
|
56
|
-
|
57
|
-
await promises.appendFile(
|
58
|
-
`${DIGIPAIR_LOGS_PATH}/consumption-daily/${current.toISOString().split('T')[0]}.jsonl`,
|
59
|
-
'\n' + JSON.stringify(line),
|
60
|
-
'utf8',
|
61
|
-
);
|
62
|
-
}
|
63
|
-
|
64
|
-
async computeDailyConsumption(params: any, _pinsSettingsList: PinsSettings[], context: any) {
|
65
|
-
const {
|
66
|
-
date,
|
67
|
-
path = context.privates.DIGIPAIR_LOGS_PATH ??
|
68
|
-
process.env['DIGIPAIR_LOGS_PATH'] ??
|
69
|
-
'./factory/logs',
|
70
|
-
} = params;
|
71
|
-
let result: any;
|
72
|
-
|
73
|
-
try {
|
74
|
-
const text = await promises.readFile(`${path}/consumption-daily/${date}.jsonl`, 'utf8');
|
75
|
-
const lines = text.split('\n').filter(line => line !== '');
|
76
|
-
result = lines.map((line: string) => JSON.parse(line));
|
77
|
-
} catch (error) {
|
78
|
-
result = [];
|
79
|
-
}
|
80
|
-
|
81
|
-
const dayLines = result.reduce((acc: any, curr: any) => {
|
82
|
-
let line = acc.find(
|
83
|
-
(line: any) =>
|
84
|
-
line.digipair === curr.digipair &&
|
85
|
-
line.reasoning === curr.reasoning &&
|
86
|
-
line.service === curr.service &&
|
87
|
-
line.model === curr.model,
|
88
|
-
);
|
89
|
-
|
90
|
-
if (!line) {
|
91
|
-
line = {
|
92
|
-
date,
|
93
|
-
digipair: curr.digipair,
|
94
|
-
reasoning: curr.reasoning,
|
95
|
-
service: curr.service,
|
96
|
-
model: curr.model,
|
97
|
-
promptTokens: 0,
|
98
|
-
completionTokens: 0,
|
99
|
-
};
|
100
|
-
acc.push(line);
|
101
|
-
}
|
102
|
-
|
103
|
-
line.promptTokens += curr.promptTokens;
|
104
|
-
line.completionTokens += curr.completionTokens;
|
105
|
-
|
106
|
-
return acc;
|
107
|
-
}, []);
|
108
|
-
|
109
|
-
await promises.appendFile(
|
110
|
-
`${path}/consumption-monthly/${date.substring(0, 7)}.jsonl`,
|
111
|
-
'\n' + dayLines.map((line: any) => JSON.stringify(line)).join('\n'),
|
112
|
-
'utf8',
|
113
|
-
);
|
114
|
-
}
|
115
|
-
|
116
|
-
async read(params: any, _pinsSettingsList: PinsSettings[], context: any) {
|
117
|
-
const {
|
118
|
-
date,
|
119
|
-
type = 'factory', // consumption-daily, consumption-monthly, factory
|
120
|
-
path = context.privates.DIGIPAIR_LOGS_PATH ??
|
121
|
-
process.env['DIGIPAIR_LOGS_PATH'] ??
|
122
|
-
'./factory/logs',
|
123
|
-
} = params;
|
124
|
-
let result: any[];
|
125
|
-
|
126
|
-
try {
|
127
|
-
const text = await promises.readFile(`${path}/${type}/${date}.jsonl`, 'utf8');
|
128
|
-
const lines = text.split('\n').filter(line => line !== '');
|
129
|
-
result = lines.map((line: string) => JSON.parse(line));
|
130
|
-
} catch (error) {
|
131
|
-
result = [];
|
132
|
-
}
|
133
|
-
|
134
|
-
return result;
|
135
|
-
}
|
136
|
-
|
137
|
-
async list(params: any, _pinsSettingsList: PinsSettings[], context: any) {
|
138
|
-
const {
|
139
|
-
type = 'factory', // consumption-daily, consumption-monthly, factory
|
140
|
-
path = context.privates.DIGIPAIR_LOGS_PATH ??
|
141
|
-
process.env['DIGIPAIR_LOGS_PATH'] ??
|
142
|
-
'./factory/logs',
|
143
|
-
} = params;
|
144
|
-
|
145
|
-
const files = (await promises.readdir(`${path}/${type}`))
|
146
|
-
.filter(file => /\.jsonl$/g.test(file))
|
147
|
-
.map(file => file.split('.')[0]);
|
148
|
-
|
149
|
-
return files;
|
150
|
-
}
|
151
|
-
|
152
|
-
async cleaning(params: any, _pinsSettingsList: PinsSettings[], context: any) {
|
153
|
-
const {
|
154
|
-
type = 'factory', // consumption-daily, consumption-monthly, factory
|
155
|
-
to,
|
156
|
-
path = context.privates.DIGIPAIR_LOGS_PATH ??
|
157
|
-
process.env['DIGIPAIR_LOGS_PATH'] ??
|
158
|
-
'./factory/logs',
|
159
|
-
} = params;
|
160
|
-
const files = await promises.readdir(`${path}/${type}`);
|
161
|
-
|
162
|
-
for (const file of files) {
|
163
|
-
const stats = await promises.stat(`${path}/${type}/${file}`);
|
164
|
-
if (stats.mtime.getTime() < to) {
|
165
|
-
promises.unlink(`${path}/${type}/${file}`);
|
166
|
-
}
|
167
|
-
}
|
168
|
-
}
|
169
|
-
}
|
170
|
-
|
171
|
-
export const initialize = (path?: string) => new LoggerService().initialize(path);
|
172
|
-
|
173
|
-
export const addLog = (context: any, type: string, message: string) =>
|
174
|
-
new LoggerService().addLog(context, type, message);
|
175
|
-
|
176
|
-
export const addConsumption = (
|
177
|
-
context: any,
|
178
|
-
service: string,
|
179
|
-
model: string,
|
180
|
-
promptTokens: number,
|
181
|
-
completionTokens: number,
|
182
|
-
) => new LoggerService().addConsumption(context, service, model, promptTokens, completionTokens);
|
183
|
-
|
184
|
-
// ----------------------------
|
185
|
-
// Methods for the skill
|
186
|
-
// ----------------------------
|
187
|
-
|
188
|
-
export const computeDailyConsumption = (
|
189
|
-
params: any,
|
190
|
-
pinsSettingsList: PinsSettings[],
|
191
|
-
context: any,
|
192
|
-
) => new LoggerService().computeDailyConsumption(params, pinsSettingsList, context);
|
193
|
-
|
194
|
-
export const read = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
|
195
|
-
new LoggerService().read(params, pinsSettingsList, context);
|
196
|
-
|
197
|
-
export const list = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
|
198
|
-
new LoggerService().list(params, pinsSettingsList, context);
|
199
|
-
|
200
|
-
export const cleaning = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
|
201
|
-
new LoggerService().cleaning(params, pinsSettingsList, context);
|
package/tsconfig.json
DELETED
package/tsconfig.lib.json
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"extends": "../../tsconfig.base.json",
|
3
|
-
"compilerOptions": {
|
4
|
-
"rootDir": "src",
|
5
|
-
"outDir": "dist",
|
6
|
-
"tsBuildInfoFile": "dist/tsconfig.lib.tsbuildinfo",
|
7
|
-
"emitDeclarationOnly": true,
|
8
|
-
"module": "esnext",
|
9
|
-
"moduleResolution": "node",
|
10
|
-
"forceConsistentCasingInFileNames": true,
|
11
|
-
"types": ["node"]
|
12
|
-
},
|
13
|
-
"include": ["src/**/*.ts"],
|
14
|
-
"references": [
|
15
|
-
{
|
16
|
-
"path": "../engine/tsconfig.lib.json"
|
17
|
-
}
|
18
|
-
]
|
19
|
-
}
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|