@autobe/utils 0.28.1 → 0.29.1
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/lib/ArrayUtil.d.ts +4 -0
- package/lib/ArrayUtil.js +38 -0
- package/lib/ArrayUtil.js.map +1 -0
- package/lib/aggregate/AutoBeFunctionCallingMetricFactory.d.ts +7 -0
- package/lib/aggregate/AutoBeFunctionCallingMetricFactory.js +35 -0
- package/lib/aggregate/AutoBeFunctionCallingMetricFactory.js.map +1 -0
- package/lib/aggregate/AutoBeProcessAggregateFactory.d.ts +13 -0
- package/lib/aggregate/AutoBeProcessAggregateFactory.js +111 -0
- package/lib/aggregate/AutoBeProcessAggregateFactory.js.map +1 -0
- package/lib/aggregate/TokenUsageComputer.d.ts +6 -0
- package/lib/aggregate/TokenUsageComputer.js +42 -0
- package/lib/aggregate/TokenUsageComputer.js.map +1 -0
- package/lib/aggregate/index.d.ts +3 -0
- package/lib/aggregate/index.js +20 -0
- package/lib/aggregate/index.js.map +1 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.js +3 -0
- package/lib/index.js.map +1 -1
- package/lib/prisma/index.d.ts +1 -0
- package/lib/prisma/index.js +18 -0
- package/lib/prisma/index.js.map +1 -0
- package/lib/prisma/writePrismaApplication.d.ts +5 -0
- package/lib/prisma/writePrismaApplication.js +342 -0
- package/lib/prisma/writePrismaApplication.js.map +1 -0
- package/package.json +3 -2
- package/src/ArrayUtil.ts +21 -0
- package/src/aggregate/AutoBeFunctionCallingMetricFactory.ts +44 -0
- package/src/aggregate/AutoBeProcessAggregateFactory.ts +152 -0
- package/src/aggregate/TokenUsageComputer.ts +49 -0
- package/src/aggregate/index.ts +3 -0
- package/src/index.ts +4 -0
- package/src/prisma/index.ts +1 -0
- package/src/prisma/writePrismaApplication.ts +439 -0
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.writePrismaApplication = writePrismaApplication;
|
|
7
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
8
|
+
const ArrayUtil_1 = require("../ArrayUtil");
|
|
9
|
+
const MapUtil_1 = require("../MapUtil");
|
|
10
|
+
const StringUtil_1 = require("../StringUtil");
|
|
11
|
+
function writePrismaApplication(props) {
|
|
12
|
+
for (const file of props.application.files)
|
|
13
|
+
for (const model of file.models)
|
|
14
|
+
fillMappingName(model);
|
|
15
|
+
return Object.assign(Object.assign({}, Object.fromEntries(props.application.files
|
|
16
|
+
.filter((file) => file.filename !== "main.prisma")
|
|
17
|
+
.map((file) => [
|
|
18
|
+
file.filename,
|
|
19
|
+
writeFile(Object.assign(Object.assign({}, props), { file })),
|
|
20
|
+
]))), { "main.prisma": props.dbms === "postgres" ? POSTGRES_MAIN_FILE : SQLITE_MAIN_FILE });
|
|
21
|
+
}
|
|
22
|
+
function writeFile(props) {
|
|
23
|
+
return props.file.models
|
|
24
|
+
.map((model) => writeModel(Object.assign(Object.assign({}, props), { model })))
|
|
25
|
+
.join("\n\n");
|
|
26
|
+
}
|
|
27
|
+
function writeModel(props) {
|
|
28
|
+
return [
|
|
29
|
+
writeComment([
|
|
30
|
+
props.model.description,
|
|
31
|
+
"",
|
|
32
|
+
...(props.model.material ? [] : [`@namespace ${props.file.namespace}`]),
|
|
33
|
+
"@author AutoBE - https://github.com/wrtnlabs/autobe",
|
|
34
|
+
].join("\n"), 80),
|
|
35
|
+
`model ${props.model.name} {`,
|
|
36
|
+
addIndent(ArrayUtil_1.ArrayUtil.paddle([writeColumns(props), writeRelations(props)]).join("\n")),
|
|
37
|
+
"}",
|
|
38
|
+
].join("\n");
|
|
39
|
+
}
|
|
40
|
+
function fillMappingName(model) {
|
|
41
|
+
const group = new Map();
|
|
42
|
+
for (const ff of model.foreignFields) {
|
|
43
|
+
MapUtil_1.MapUtil.take(group, ff.relation.targetModel, () => []).push(ff);
|
|
44
|
+
if (ff.relation.targetModel == model.name)
|
|
45
|
+
ff.relation.mappingName = "recursive";
|
|
46
|
+
}
|
|
47
|
+
for (const array of group.values())
|
|
48
|
+
if (array.length !== 1)
|
|
49
|
+
for (const ff of array)
|
|
50
|
+
ff.relation.mappingName = shortName(`${model.name}_of_${ff.name}`);
|
|
51
|
+
}
|
|
52
|
+
/* -----------------------------------------------------------
|
|
53
|
+
COLUMNS
|
|
54
|
+
----------------------------------------------------------- */
|
|
55
|
+
function writeColumns(props) {
|
|
56
|
+
return [
|
|
57
|
+
"//----",
|
|
58
|
+
"// COLUMNS",
|
|
59
|
+
"//----",
|
|
60
|
+
writePrimary({
|
|
61
|
+
dbms: props.dbms,
|
|
62
|
+
model: props.model,
|
|
63
|
+
field: props.model.primaryField,
|
|
64
|
+
}),
|
|
65
|
+
...props.model.foreignFields
|
|
66
|
+
.map((x) => [
|
|
67
|
+
"",
|
|
68
|
+
writeField({
|
|
69
|
+
dbms: props.dbms,
|
|
70
|
+
field: x,
|
|
71
|
+
}),
|
|
72
|
+
])
|
|
73
|
+
.flat(),
|
|
74
|
+
...props.model.plainFields
|
|
75
|
+
.map((x) => [
|
|
76
|
+
"",
|
|
77
|
+
writeField({
|
|
78
|
+
dbms: props.dbms,
|
|
79
|
+
field: x,
|
|
80
|
+
}),
|
|
81
|
+
])
|
|
82
|
+
.flat(),
|
|
83
|
+
];
|
|
84
|
+
}
|
|
85
|
+
function writePrimary(props) {
|
|
86
|
+
const type = props.dbms === "postgres" ? POSTGRES_PHYSICAL_TYPES.uuid : undefined;
|
|
87
|
+
const pkeyName = `${props.model.name}__pkey`;
|
|
88
|
+
const signature = pkeyName.length <= MAX_IDENTIFIER_LENGTH
|
|
89
|
+
? "@id"
|
|
90
|
+
: `@id(map: "${shortName(pkeyName)}")`;
|
|
91
|
+
return [
|
|
92
|
+
writeComment(props.field.description, 78),
|
|
93
|
+
`${props.field.name} String ${signature}${type ? ` ${type}` : ""}`,
|
|
94
|
+
].join("\n");
|
|
95
|
+
}
|
|
96
|
+
function writeField(props) {
|
|
97
|
+
const logical = LOGICAL_TYPES[props.field.type];
|
|
98
|
+
const physical = props.dbms === "postgres"
|
|
99
|
+
? POSTGRES_PHYSICAL_TYPES[props.field.type]
|
|
100
|
+
: undefined;
|
|
101
|
+
return [
|
|
102
|
+
writeComment(props.field.description, 78),
|
|
103
|
+
[
|
|
104
|
+
props.field.name,
|
|
105
|
+
`${logical}${props.field.nullable ? "?" : ""}`,
|
|
106
|
+
...(physical ? [physical] : []),
|
|
107
|
+
].join(" "),
|
|
108
|
+
].join("\n");
|
|
109
|
+
}
|
|
110
|
+
/* -----------------------------------------------------------
|
|
111
|
+
RELATIONS
|
|
112
|
+
----------------------------------------------------------- */
|
|
113
|
+
function writeRelations(props) {
|
|
114
|
+
const hasRelationships = props.application.files
|
|
115
|
+
.map((otherFile) => otherFile.models.map((otherModel) => otherModel.foreignFields
|
|
116
|
+
.filter((otherForeign) => otherForeign.relation.targetModel === props.model.name)
|
|
117
|
+
.map((otherForeign) => ({
|
|
118
|
+
modelName: otherModel.name,
|
|
119
|
+
unique: otherForeign.unique,
|
|
120
|
+
mappingName: otherForeign.relation.mappingName,
|
|
121
|
+
}))))
|
|
122
|
+
.flat(2);
|
|
123
|
+
const foreignIndexes = props.model.foreignFields.filter((f) => {
|
|
124
|
+
if (f.unique === true)
|
|
125
|
+
return props.model.uniqueIndexes.every((u) => u.fieldNames.length !== 1 || u.fieldNames[0] !== f.name);
|
|
126
|
+
return (props.model.uniqueIndexes.every((u) => u.fieldNames[0] !== f.name) &&
|
|
127
|
+
props.model.plainIndexes.every((p) => p.fieldNames[0] !== f.name));
|
|
128
|
+
});
|
|
129
|
+
const contents = [
|
|
130
|
+
props.model.foreignFields.map((foreign) => writeConstraint({
|
|
131
|
+
dbms: props.dbms,
|
|
132
|
+
model: props.model,
|
|
133
|
+
foreign,
|
|
134
|
+
})),
|
|
135
|
+
hasRelationships.map((r) => {
|
|
136
|
+
var _a;
|
|
137
|
+
return [
|
|
138
|
+
(_a = r.mappingName) !== null && _a !== void 0 ? _a : r.modelName,
|
|
139
|
+
`${r.modelName}${r.unique ? "?" : "[]"}`,
|
|
140
|
+
...(r.mappingName ? [`@relation("${r.mappingName}")`] : []),
|
|
141
|
+
].join(" ");
|
|
142
|
+
}),
|
|
143
|
+
foreignIndexes.map((field) => writeForeignIndex({
|
|
144
|
+
model: props.model,
|
|
145
|
+
field,
|
|
146
|
+
})),
|
|
147
|
+
[
|
|
148
|
+
...props.model.uniqueIndexes.map((unique) => writeUniqueIndex({
|
|
149
|
+
model: props.model,
|
|
150
|
+
unique,
|
|
151
|
+
})),
|
|
152
|
+
...props.model.plainIndexes.map((plain) => writePlainIndex({
|
|
153
|
+
model: props.model,
|
|
154
|
+
plain,
|
|
155
|
+
})),
|
|
156
|
+
...(props.dbms === "postgres"
|
|
157
|
+
? props.model.ginIndexes.map((gin) => writeGinIndex({
|
|
158
|
+
model: props.model,
|
|
159
|
+
gin,
|
|
160
|
+
}))
|
|
161
|
+
: []),
|
|
162
|
+
],
|
|
163
|
+
];
|
|
164
|
+
if (contents.every((c) => c.length === 0))
|
|
165
|
+
return [];
|
|
166
|
+
return [
|
|
167
|
+
"//----",
|
|
168
|
+
"// RELATIONS",
|
|
169
|
+
"//----",
|
|
170
|
+
// paddled content
|
|
171
|
+
...ArrayUtil_1.ArrayUtil.paddle(contents),
|
|
172
|
+
];
|
|
173
|
+
}
|
|
174
|
+
function writeConstraint(props) {
|
|
175
|
+
// spellchecker:ignore-next-line
|
|
176
|
+
const name = `${props.model.name}_${props.foreign.name}_rela`;
|
|
177
|
+
const tooMuchLong = props.dbms === "postgres" && name.length > MAX_IDENTIFIER_LENGTH;
|
|
178
|
+
const body = [
|
|
179
|
+
props.foreign.relation.name,
|
|
180
|
+
`${props.foreign.relation.targetModel}${props.foreign.nullable ? "?" : ""}`,
|
|
181
|
+
`@relation(${[
|
|
182
|
+
...(props.foreign.relation.mappingName
|
|
183
|
+
? [`"${props.foreign.relation.mappingName}"`]
|
|
184
|
+
: []),
|
|
185
|
+
`fields: [${props.foreign.name}]`,
|
|
186
|
+
`references: [id]`,
|
|
187
|
+
`onDelete: Cascade`,
|
|
188
|
+
...(tooMuchLong ? [`map: "${shortName(name)}"`] : []),
|
|
189
|
+
].join(", ")})`,
|
|
190
|
+
].join(" ");
|
|
191
|
+
return tooMuchLong
|
|
192
|
+
? StringUtil_1.StringUtil.trim `
|
|
193
|
+
// spellchecker: ignore-next-line
|
|
194
|
+
${body}
|
|
195
|
+
`
|
|
196
|
+
: body;
|
|
197
|
+
}
|
|
198
|
+
function writeForeignIndex(props) {
|
|
199
|
+
const name = `${props.model.name}_${props.field.name}_fkey`;
|
|
200
|
+
const prefix = `@@${props.field.unique === true ? "unique" : "index"}([${props.field.name}]`;
|
|
201
|
+
if (name.length <= MAX_IDENTIFIER_LENGTH)
|
|
202
|
+
return `${prefix})`;
|
|
203
|
+
return StringUtil_1.StringUtil.trim `
|
|
204
|
+
// spellchecker: ignore-next-line
|
|
205
|
+
${prefix}, map: "${shortName(name)}")
|
|
206
|
+
`;
|
|
207
|
+
}
|
|
208
|
+
function writeUniqueIndex(props) {
|
|
209
|
+
const name = `${props.model.name}_${props.unique.fieldNames.join("_")}_key`;
|
|
210
|
+
const prefix = `@@unique([${props.unique.fieldNames.join(", ")}]`;
|
|
211
|
+
if (name.length <= MAX_IDENTIFIER_LENGTH)
|
|
212
|
+
return `${prefix})`;
|
|
213
|
+
return StringUtil_1.StringUtil.trim `
|
|
214
|
+
// spellchecker: ignore-next-line
|
|
215
|
+
${prefix}, map: "${shortName(name)}")
|
|
216
|
+
`;
|
|
217
|
+
}
|
|
218
|
+
function writePlainIndex(props) {
|
|
219
|
+
const name = `${props.model.name}_${props.plain.fieldNames.join("_")}_idx`;
|
|
220
|
+
const prefix = `@@index([${props.plain.fieldNames.join(", ")}]`;
|
|
221
|
+
if (name.length <= MAX_IDENTIFIER_LENGTH)
|
|
222
|
+
return `${prefix})`;
|
|
223
|
+
return StringUtil_1.StringUtil.trim `
|
|
224
|
+
// spellchecker: ignore-next-line
|
|
225
|
+
${prefix}, map: "${shortName(name)}")
|
|
226
|
+
`;
|
|
227
|
+
}
|
|
228
|
+
function writeGinIndex(props) {
|
|
229
|
+
const name = `${props.model.name}_${props.gin.fieldName}_idx`;
|
|
230
|
+
const prefix = `@@index([${props.gin.fieldName}(ops: raw("gin_trgm_ops"))], type: Gin`;
|
|
231
|
+
if (name.length <= MAX_IDENTIFIER_LENGTH)
|
|
232
|
+
return `${prefix})`;
|
|
233
|
+
return StringUtil_1.StringUtil.trim `
|
|
234
|
+
// spellchecker: ignore-next-line
|
|
235
|
+
${prefix}, map: "${shortName(name)}")
|
|
236
|
+
`;
|
|
237
|
+
}
|
|
238
|
+
/* -----------------------------------------------------------
|
|
239
|
+
BACKGROUND
|
|
240
|
+
----------------------------------------------------------- */
|
|
241
|
+
function writeComment(content, length) {
|
|
242
|
+
return content
|
|
243
|
+
.split("\r\n")
|
|
244
|
+
.join("\n")
|
|
245
|
+
.split("\n")
|
|
246
|
+
.map((line) => line.trim())
|
|
247
|
+
.map((line) => {
|
|
248
|
+
// 77자에서 "/// " 4자를 뺀 73자가 실제 컨텐츠 최대 길이
|
|
249
|
+
if (line.length <= length - 4)
|
|
250
|
+
return [line];
|
|
251
|
+
const words = line.split(" ");
|
|
252
|
+
const result = [];
|
|
253
|
+
let currentLine = "";
|
|
254
|
+
for (const word of words) {
|
|
255
|
+
const potentialLine = currentLine ? `${currentLine} ${word}` : word;
|
|
256
|
+
if (potentialLine.length <= 73) {
|
|
257
|
+
currentLine = potentialLine;
|
|
258
|
+
}
|
|
259
|
+
else {
|
|
260
|
+
if (currentLine)
|
|
261
|
+
result.push(currentLine);
|
|
262
|
+
currentLine = word;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
if (currentLine)
|
|
266
|
+
result.push(currentLine);
|
|
267
|
+
return result;
|
|
268
|
+
})
|
|
269
|
+
.flat()
|
|
270
|
+
.map((str) => `///${str.length ? ` ${str}` : ""}`)
|
|
271
|
+
.join("\n")
|
|
272
|
+
.trim();
|
|
273
|
+
}
|
|
274
|
+
function addIndent(content) {
|
|
275
|
+
return content
|
|
276
|
+
.split("\r\n")
|
|
277
|
+
.join("\n")
|
|
278
|
+
.split("\n")
|
|
279
|
+
.map((str) => ` ${str}`)
|
|
280
|
+
.join("\n");
|
|
281
|
+
}
|
|
282
|
+
function shortName(name) {
|
|
283
|
+
if (name.length <= MAX_IDENTIFIER_LENGTH)
|
|
284
|
+
return name;
|
|
285
|
+
const hash = crypto_1.default
|
|
286
|
+
.createHash("md5")
|
|
287
|
+
.update(name)
|
|
288
|
+
.digest("hex")
|
|
289
|
+
.substring(0, HASH_TRUNCATION_LENGTH);
|
|
290
|
+
return `${name.substring(0, MAX_IDENTIFIER_LENGTH - HASH_TRUNCATION_LENGTH - 1)}_${hash}`;
|
|
291
|
+
}
|
|
292
|
+
const LOGICAL_TYPES = {
|
|
293
|
+
// native types
|
|
294
|
+
boolean: "Boolean",
|
|
295
|
+
int: "Int",
|
|
296
|
+
double: "Float",
|
|
297
|
+
string: "String",
|
|
298
|
+
// formats
|
|
299
|
+
datetime: "DateTime",
|
|
300
|
+
uuid: "String",
|
|
301
|
+
uri: "String",
|
|
302
|
+
};
|
|
303
|
+
const POSTGRES_PHYSICAL_TYPES = {
|
|
304
|
+
int: "@db.Integer",
|
|
305
|
+
double: "@db.DoublePrecision",
|
|
306
|
+
uuid: "@db.Uuid",
|
|
307
|
+
datetime: "@db.Timestamptz",
|
|
308
|
+
uri: "@db.VarChar(80000)",
|
|
309
|
+
};
|
|
310
|
+
const POSTGRES_MAIN_FILE = StringUtil_1.StringUtil.trim `
|
|
311
|
+
generator client {
|
|
312
|
+
provider = "prisma-client-js"
|
|
313
|
+
engineType = "client"
|
|
314
|
+
previewFeatures = ["postgresqlExtensions", "views"]
|
|
315
|
+
}
|
|
316
|
+
datasource db {
|
|
317
|
+
provider = "postgresql"
|
|
318
|
+
url = env("DATABASE_URL")
|
|
319
|
+
extensions = [pg_trgm]
|
|
320
|
+
}
|
|
321
|
+
generator markdown {
|
|
322
|
+
provider = "prisma-markdown"
|
|
323
|
+
output = "../../docs/ERD.md"
|
|
324
|
+
}
|
|
325
|
+
`;
|
|
326
|
+
const SQLITE_MAIN_FILE = StringUtil_1.StringUtil.trim `
|
|
327
|
+
generator client {
|
|
328
|
+
provider = "prisma-client-js"
|
|
329
|
+
engineType = "client"
|
|
330
|
+
}
|
|
331
|
+
datasource db {
|
|
332
|
+
provider = "sqlite"
|
|
333
|
+
url = "file:../db.sqlite"
|
|
334
|
+
}
|
|
335
|
+
generator markdown {
|
|
336
|
+
provider = "prisma-markdown"
|
|
337
|
+
output = "../../docs/ERD.md"
|
|
338
|
+
}
|
|
339
|
+
`;
|
|
340
|
+
const MAX_IDENTIFIER_LENGTH = 63;
|
|
341
|
+
const HASH_TRUNCATION_LENGTH = 8;
|
|
342
|
+
//# sourceMappingURL=writePrismaApplication.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"writePrismaApplication.js","sourceRoot":"","sources":["../../src/prisma/writePrismaApplication.ts"],"names":[],"mappings":";;;;;AAOA,wDAqBC;AA3BD,oDAA4B;AAE5B,4CAAyC;AACzC,wCAAqC;AACrC,8CAA2C;AAE3C,SAAgB,sBAAsB,CAAC,KAGtC;IACC,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,WAAW,CAAC,KAAK;QACxC,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,MAAM;YAAE,eAAe,CAAC,KAAK,CAAC,CAAC;IAC1D,uCACK,MAAM,CAAC,WAAW,CACnB,KAAK,CAAC,WAAW,CAAC,KAAK;SACpB,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,KAAK,aAAa,CAAC;SACjD,GAAG,CAAC,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AAI,qBAAqB;QAAE,OAAO,IAAI,CAAC;IACtD,MAAM,IAAI,GAAW,gBAAM;SACxB,UAAU,CAAC,KAAK,CAAC;SACjB,MAAM,CAAC,IAAI,CAAC;SACZ,MAAM,CAAC,KAAK,CAAC;SACb,SAAS,CAAC,CAAC,EAAE,sBAAsB,CAAC,CAAC;IACxC,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,qBAAqB,GAAG,sBAAsB,GAAG,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC;AAC5F,CAAC;AAED,MAAM,aAAa,GAAG;IACpB,eAAe;IACf,OAAO,EAAE,SAAS;IAClB,GAAG,EAAE,KAAK;IACV,MAAM,EAAE,OAAO;IACf,MAAM,EAAE,QAAQ;IAChB,UAAU;IACV,QAAQ,EAAE,UAAU;IACpB,IAAI,EAAE,QAAQ;IACd,GAAG,EAAE,QAAQ;CACd,CAAC;AACF,MAAM,uBAAuB,GAAG;IAC9B,GAAG,EAAE,aAAa;IAClB,MAAM,EAAE,qBAAqB;IAC7B,IAAI,EAAE,UAAU;IAChB,QAAQ,EAAE,iBAAiB;IAC3B,GAAG,EAAE,oBAAoB;CAC1B,CAAC;AAEF,MAAM,kBAAkB,GAAG,uBAAU,CAAC,IAAI,CAAA;;;;;;;;;;;;;;;CAezC,CAAC;AACF,MAAM,gBAAgB,GAAG,uBAAU,CAAC,IAAI,CAAA;;;;;;;;;;;;;CAavC,CAAC;AACF,MAAM,qBAAqB,GAAG,EAAE,CAAC;AACjC,MAAM,sBAAsB,GAAG,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autobe/utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.29.1",
|
|
4
4
|
"description": "AI backend server code generator",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"keywords": [],
|
|
@@ -27,9 +27,10 @@
|
|
|
27
27
|
"@samchon/openapi": "^5.0.1",
|
|
28
28
|
"tstl": "^3.0.0",
|
|
29
29
|
"typia": "^10.0.2",
|
|
30
|
-
"@autobe/interface": "^0.
|
|
30
|
+
"@autobe/interface": "^0.29.1"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
+
"@types/node": "^24.10.1",
|
|
33
34
|
"rimraf": "^6.0.1",
|
|
34
35
|
"ts-patch": "^3.3.0",
|
|
35
36
|
"typescript": "~5.9.3"
|
package/src/ArrayUtil.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export namespace ArrayUtil {
|
|
2
|
+
export async function asyncMap<T, U>(
|
|
3
|
+
array: T[],
|
|
4
|
+
callback: (value: T, index: number, array: T[]) => Promise<U>,
|
|
5
|
+
): Promise<U[]> {
|
|
6
|
+
const result: U[] = new Array(array.length);
|
|
7
|
+
for (let i = 0; i < array.length; i++)
|
|
8
|
+
result[i] = await callback(array[i], i, array);
|
|
9
|
+
return result;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function paddle(contents: string[][]): string[] {
|
|
13
|
+
const output: string[] = [];
|
|
14
|
+
contents.forEach((c) => {
|
|
15
|
+
if (c.length === 0) return;
|
|
16
|
+
else if (output.length === 0) output.push(...c);
|
|
17
|
+
else output.push("", ...c);
|
|
18
|
+
});
|
|
19
|
+
return output;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { AutoBeFunctionCallingMetric } from "@autobe/interface";
|
|
2
|
+
|
|
3
|
+
export namespace AutoBeFunctionCallingMetricFactory {
|
|
4
|
+
export const create = (): AutoBeFunctionCallingMetric => ({
|
|
5
|
+
attempt: 0,
|
|
6
|
+
success: 0,
|
|
7
|
+
consent: 0,
|
|
8
|
+
validationFailure: 0,
|
|
9
|
+
invalidJson: 0,
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
export const increment = (
|
|
13
|
+
x: AutoBeFunctionCallingMetric,
|
|
14
|
+
y: AutoBeFunctionCallingMetric,
|
|
15
|
+
): void => {
|
|
16
|
+
x.attempt += y.attempt;
|
|
17
|
+
x.success += y.success;
|
|
18
|
+
x.consent += y.consent;
|
|
19
|
+
x.validationFailure += y.validationFailure;
|
|
20
|
+
x.invalidJson += y.invalidJson;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const plus = (
|
|
24
|
+
x: AutoBeFunctionCallingMetric,
|
|
25
|
+
y: AutoBeFunctionCallingMetric,
|
|
26
|
+
): AutoBeFunctionCallingMetric => ({
|
|
27
|
+
attempt: x.attempt + y.attempt,
|
|
28
|
+
success: x.success + y.success,
|
|
29
|
+
consent: x.consent + y.consent,
|
|
30
|
+
validationFailure: x.validationFailure + y.validationFailure,
|
|
31
|
+
invalidJson: x.invalidJson + y.invalidJson,
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
export const minus = (
|
|
35
|
+
x: AutoBeFunctionCallingMetric,
|
|
36
|
+
y: AutoBeFunctionCallingMetric,
|
|
37
|
+
): AutoBeFunctionCallingMetric => ({
|
|
38
|
+
attempt: x.attempt - y.attempt,
|
|
39
|
+
success: x.success - y.success,
|
|
40
|
+
consent: x.consent - y.consent,
|
|
41
|
+
validationFailure: x.validationFailure - y.validationFailure,
|
|
42
|
+
invalidJson: x.invalidJson - y.invalidJson,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AutoBeAggregateEventBase,
|
|
3
|
+
AutoBePhase,
|
|
4
|
+
AutoBeProcessAggregate,
|
|
5
|
+
AutoBeProcessAggregateCollection,
|
|
6
|
+
} from "@autobe/interface";
|
|
7
|
+
|
|
8
|
+
import { AutoBeFunctionCallingMetricFactory } from "./AutoBeFunctionCallingMetricFactory";
|
|
9
|
+
import { TokenUsageComputer } from "./TokenUsageComputer";
|
|
10
|
+
|
|
11
|
+
export namespace AutoBeProcessAggregateFactory {
|
|
12
|
+
export const createAggregate = (): AutoBeProcessAggregate => ({
|
|
13
|
+
metric: AutoBeFunctionCallingMetricFactory.create(),
|
|
14
|
+
tokenUsage: {
|
|
15
|
+
total: 0,
|
|
16
|
+
input: {
|
|
17
|
+
total: 0,
|
|
18
|
+
cached: 0,
|
|
19
|
+
},
|
|
20
|
+
output: {
|
|
21
|
+
total: 0,
|
|
22
|
+
reasoning: 0,
|
|
23
|
+
accepted_prediction: 0,
|
|
24
|
+
rejected_prediction: 0,
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
export const createCollection = <
|
|
30
|
+
Phase extends AutoBePhase | "all",
|
|
31
|
+
>(): AutoBeProcessAggregateCollection<Phase> =>
|
|
32
|
+
({
|
|
33
|
+
total: createAggregate(),
|
|
34
|
+
}) satisfies AutoBeProcessAggregateCollection as AutoBeProcessAggregateCollection<Phase>;
|
|
35
|
+
|
|
36
|
+
export const computeTotal = <Phase extends AutoBePhase | "all">(
|
|
37
|
+
collection: AutoBeProcessAggregateCollection<Phase>,
|
|
38
|
+
): AutoBeProcessAggregate => {
|
|
39
|
+
const total: AutoBeProcessAggregate = createAggregate();
|
|
40
|
+
for (const [key, value] of Object.entries(collection)) {
|
|
41
|
+
if (key === "total") continue;
|
|
42
|
+
AutoBeFunctionCallingMetricFactory.increment(total.metric, value.metric);
|
|
43
|
+
TokenUsageComputer.increment(total.tokenUsage, value.tokenUsage);
|
|
44
|
+
}
|
|
45
|
+
return total;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export const emplaceEvent = <
|
|
49
|
+
Event extends AutoBeAggregateEventBase & {
|
|
50
|
+
type: string;
|
|
51
|
+
},
|
|
52
|
+
>(
|
|
53
|
+
collection: AutoBeProcessAggregateCollection,
|
|
54
|
+
event: Event,
|
|
55
|
+
): void => {
|
|
56
|
+
(collection as any)[event.type] ??= createAggregate();
|
|
57
|
+
collection.total ??= computeTotal(collection);
|
|
58
|
+
|
|
59
|
+
const local: AutoBeProcessAggregate = (collection as any)[
|
|
60
|
+
event.type
|
|
61
|
+
] as AutoBeProcessAggregate;
|
|
62
|
+
const total: AutoBeProcessAggregate = collection.total;
|
|
63
|
+
|
|
64
|
+
AutoBeFunctionCallingMetricFactory.increment(local.metric, event.metric);
|
|
65
|
+
AutoBeFunctionCallingMetricFactory.increment(total.metric, event.metric);
|
|
66
|
+
TokenUsageComputer.increment(local.tokenUsage, event.tokenUsage);
|
|
67
|
+
TokenUsageComputer.increment(total.tokenUsage, event.tokenUsage);
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export const filterPhase = <Phase extends AutoBePhase>(
|
|
71
|
+
collection: AutoBeProcessAggregateCollection,
|
|
72
|
+
phase: Phase,
|
|
73
|
+
): AutoBeProcessAggregateCollection<Phase> => {
|
|
74
|
+
const result: AutoBeProcessAggregateCollection<Phase> = createCollection();
|
|
75
|
+
for (const [key, value] of Object.entries(collection)) {
|
|
76
|
+
if (key === "total") continue;
|
|
77
|
+
else if (key.startsWith(phase) === false) continue;
|
|
78
|
+
|
|
79
|
+
(result as any)[key] = value;
|
|
80
|
+
AutoBeFunctionCallingMetricFactory.increment(
|
|
81
|
+
result.total.metric,
|
|
82
|
+
value.metric,
|
|
83
|
+
);
|
|
84
|
+
TokenUsageComputer.increment(result.total.tokenUsage, value.tokenUsage);
|
|
85
|
+
}
|
|
86
|
+
return result;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
export const reduce = (
|
|
90
|
+
collections: AutoBeProcessAggregateCollection[],
|
|
91
|
+
): AutoBeProcessAggregateCollection => {
|
|
92
|
+
const result: AutoBeProcessAggregateCollection = createCollection();
|
|
93
|
+
for (const collection of collections) {
|
|
94
|
+
for (const [key, value] of Object.entries(collection)) {
|
|
95
|
+
if (key === "total") continue;
|
|
96
|
+
(result as any)[key] ??= createAggregate();
|
|
97
|
+
const local: AutoBeProcessAggregate = (result as any)[
|
|
98
|
+
key
|
|
99
|
+
] as AutoBeProcessAggregate;
|
|
100
|
+
AutoBeFunctionCallingMetricFactory.increment(
|
|
101
|
+
local.metric,
|
|
102
|
+
value.metric,
|
|
103
|
+
);
|
|
104
|
+
TokenUsageComputer.increment(local.tokenUsage, value.tokenUsage);
|
|
105
|
+
AutoBeFunctionCallingMetricFactory.increment(
|
|
106
|
+
result.total.metric,
|
|
107
|
+
value.metric,
|
|
108
|
+
);
|
|
109
|
+
TokenUsageComputer.increment(result.total.tokenUsage, value.tokenUsage);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
result.total ??= createAggregate();
|
|
113
|
+
Object.assign(result.total, computeTotal(result));
|
|
114
|
+
return result;
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
export const increment = (
|
|
118
|
+
x: AutoBeProcessAggregateCollection,
|
|
119
|
+
y: AutoBeProcessAggregateCollection,
|
|
120
|
+
): void => {
|
|
121
|
+
for (const [key, value] of Object.entries(y)) {
|
|
122
|
+
if (key === "total") continue;
|
|
123
|
+
(x as any)[key] ??= createAggregate();
|
|
124
|
+
const local: AutoBeProcessAggregate = (x as any)[
|
|
125
|
+
key
|
|
126
|
+
] as AutoBeProcessAggregate;
|
|
127
|
+
AutoBeFunctionCallingMetricFactory.increment(local.metric, value.metric);
|
|
128
|
+
}
|
|
129
|
+
x.total ??= createAggregate();
|
|
130
|
+
Object.assign(x.total, computeTotal(x));
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
export const minus = (
|
|
134
|
+
x: AutoBeProcessAggregateCollection,
|
|
135
|
+
y: AutoBeProcessAggregateCollection,
|
|
136
|
+
): AutoBeProcessAggregateCollection => {
|
|
137
|
+
const result = JSON.parse(
|
|
138
|
+
JSON.stringify(x),
|
|
139
|
+
) as AutoBeProcessAggregateCollection;
|
|
140
|
+
for (const [key, value] of Object.entries(y)) {
|
|
141
|
+
if (key === "total") continue;
|
|
142
|
+
(result as any)[key] ??= createAggregate();
|
|
143
|
+
const local: AutoBeProcessAggregate = (result as any)[
|
|
144
|
+
key
|
|
145
|
+
] as AutoBeProcessAggregate;
|
|
146
|
+
AutoBeFunctionCallingMetricFactory.minus(local.metric, value.metric);
|
|
147
|
+
}
|
|
148
|
+
result.total ??= createAggregate();
|
|
149
|
+
Object.assign(result.total, computeTotal(result));
|
|
150
|
+
return result;
|
|
151
|
+
};
|
|
152
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { IAutoBeTokenUsageJson } from "@autobe/interface";
|
|
2
|
+
|
|
3
|
+
export namespace TokenUsageComputer {
|
|
4
|
+
export const zero = (): IAutoBeTokenUsageJson.IComponent => ({
|
|
5
|
+
total: 0,
|
|
6
|
+
input: {
|
|
7
|
+
total: 0,
|
|
8
|
+
cached: 0,
|
|
9
|
+
},
|
|
10
|
+
output: {
|
|
11
|
+
total: 0,
|
|
12
|
+
reasoning: 0,
|
|
13
|
+
accepted_prediction: 0,
|
|
14
|
+
rejected_prediction: 0,
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
export const plus = (
|
|
19
|
+
x: IAutoBeTokenUsageJson.IComponent,
|
|
20
|
+
y: IAutoBeTokenUsageJson.IComponent,
|
|
21
|
+
): IAutoBeTokenUsageJson.IComponent => ({
|
|
22
|
+
total: x.total + y.total,
|
|
23
|
+
input: {
|
|
24
|
+
total: x.input.total + y.input.total,
|
|
25
|
+
cached: x.input.cached + y.input.cached,
|
|
26
|
+
},
|
|
27
|
+
output: {
|
|
28
|
+
total: x.output.total + y.output.total,
|
|
29
|
+
reasoning: x.output.reasoning + y.output.reasoning,
|
|
30
|
+
accepted_prediction:
|
|
31
|
+
x.output.accepted_prediction + y.output.accepted_prediction,
|
|
32
|
+
rejected_prediction:
|
|
33
|
+
x.output.rejected_prediction + y.output.rejected_prediction,
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
export const increment = (
|
|
38
|
+
x: IAutoBeTokenUsageJson.IComponent,
|
|
39
|
+
y: IAutoBeTokenUsageJson.IComponent,
|
|
40
|
+
): void => {
|
|
41
|
+
x.total += y.total;
|
|
42
|
+
x.input.total += y.input.total;
|
|
43
|
+
x.input.cached += y.input.cached;
|
|
44
|
+
x.output.total += y.output.total;
|
|
45
|
+
x.output.reasoning += y.output.reasoning;
|
|
46
|
+
x.output.accepted_prediction += y.output.accepted_prediction;
|
|
47
|
+
x.output.rejected_prediction += y.output.rejected_prediction;
|
|
48
|
+
};
|
|
49
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./writePrismaApplication";
|