@elizaos/plugin-trajectory-logger 2.0.0-alpha.12 → 2.0.0-alpha.15
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/dist/node/index.node.js +2100 -67
- package/dist/node/index.node.js.map +34 -4
- package/package.json +3 -6
package/dist/node/index.node.js
CHANGED
|
@@ -1,5 +1,1801 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __export = (target, all) => {
|
|
3
|
+
for (var name in all)
|
|
4
|
+
__defProp(target, name, {
|
|
5
|
+
get: all[name],
|
|
6
|
+
enumerable: true,
|
|
7
|
+
configurable: true,
|
|
8
|
+
set: (newValue) => all[name] = () => newValue
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
12
|
+
|
|
13
|
+
// ../../../../node_modules/drizzle-orm/entity.js
|
|
14
|
+
function is(value, type) {
|
|
15
|
+
if (!value || typeof value !== "object") {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
if (value instanceof type) {
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
if (!Object.prototype.hasOwnProperty.call(type, entityKind)) {
|
|
22
|
+
throw new Error(`Class "${type.name ?? "<unknown>"}" doesn't look like a Drizzle entity. If this is incorrect and the class is provided by Drizzle, please report this as a bug.`);
|
|
23
|
+
}
|
|
24
|
+
let cls = Object.getPrototypeOf(value).constructor;
|
|
25
|
+
if (cls) {
|
|
26
|
+
while (cls) {
|
|
27
|
+
if (entityKind in cls && cls[entityKind] === type[entityKind]) {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
cls = Object.getPrototypeOf(cls);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
var entityKind, hasOwnEntityKind;
|
|
36
|
+
var init_entity = __esm(() => {
|
|
37
|
+
entityKind = Symbol.for("drizzle:entityKind");
|
|
38
|
+
hasOwnEntityKind = Symbol.for("drizzle:hasOwnEntityKind");
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
// ../../../../node_modules/drizzle-orm/column.js
|
|
42
|
+
var Column;
|
|
43
|
+
var init_column = __esm(() => {
|
|
44
|
+
init_entity();
|
|
45
|
+
Column = class Column {
|
|
46
|
+
constructor(table, config) {
|
|
47
|
+
this.table = table;
|
|
48
|
+
this.config = config;
|
|
49
|
+
this.name = config.name;
|
|
50
|
+
this.keyAsName = config.keyAsName;
|
|
51
|
+
this.notNull = config.notNull;
|
|
52
|
+
this.default = config.default;
|
|
53
|
+
this.defaultFn = config.defaultFn;
|
|
54
|
+
this.onUpdateFn = config.onUpdateFn;
|
|
55
|
+
this.hasDefault = config.hasDefault;
|
|
56
|
+
this.primary = config.primaryKey;
|
|
57
|
+
this.isUnique = config.isUnique;
|
|
58
|
+
this.uniqueName = config.uniqueName;
|
|
59
|
+
this.uniqueType = config.uniqueType;
|
|
60
|
+
this.dataType = config.dataType;
|
|
61
|
+
this.columnType = config.columnType;
|
|
62
|
+
this.generated = config.generated;
|
|
63
|
+
this.generatedIdentity = config.generatedIdentity;
|
|
64
|
+
}
|
|
65
|
+
static [entityKind] = "Column";
|
|
66
|
+
name;
|
|
67
|
+
keyAsName;
|
|
68
|
+
primary;
|
|
69
|
+
notNull;
|
|
70
|
+
default;
|
|
71
|
+
defaultFn;
|
|
72
|
+
onUpdateFn;
|
|
73
|
+
hasDefault;
|
|
74
|
+
isUnique;
|
|
75
|
+
uniqueName;
|
|
76
|
+
uniqueType;
|
|
77
|
+
dataType;
|
|
78
|
+
columnType;
|
|
79
|
+
enumValues = undefined;
|
|
80
|
+
generated = undefined;
|
|
81
|
+
generatedIdentity = undefined;
|
|
82
|
+
config;
|
|
83
|
+
mapFromDriverValue(value) {
|
|
84
|
+
return value;
|
|
85
|
+
}
|
|
86
|
+
mapToDriverValue(value) {
|
|
87
|
+
return value;
|
|
88
|
+
}
|
|
89
|
+
shouldDisableInsert() {
|
|
90
|
+
return this.config.generated !== undefined && this.config.generated.type !== "byDefault";
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
// ../../../../node_modules/drizzle-orm/column-builder.js
|
|
96
|
+
var ColumnBuilder;
|
|
97
|
+
var init_column_builder = __esm(() => {
|
|
98
|
+
init_entity();
|
|
99
|
+
ColumnBuilder = class ColumnBuilder {
|
|
100
|
+
static [entityKind] = "ColumnBuilder";
|
|
101
|
+
config;
|
|
102
|
+
constructor(name, dataType, columnType) {
|
|
103
|
+
this.config = {
|
|
104
|
+
name,
|
|
105
|
+
keyAsName: name === "",
|
|
106
|
+
notNull: false,
|
|
107
|
+
default: undefined,
|
|
108
|
+
hasDefault: false,
|
|
109
|
+
primaryKey: false,
|
|
110
|
+
isUnique: false,
|
|
111
|
+
uniqueName: undefined,
|
|
112
|
+
uniqueType: undefined,
|
|
113
|
+
dataType,
|
|
114
|
+
columnType,
|
|
115
|
+
generated: undefined
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
$type() {
|
|
119
|
+
return this;
|
|
120
|
+
}
|
|
121
|
+
notNull() {
|
|
122
|
+
this.config.notNull = true;
|
|
123
|
+
return this;
|
|
124
|
+
}
|
|
125
|
+
default(value) {
|
|
126
|
+
this.config.default = value;
|
|
127
|
+
this.config.hasDefault = true;
|
|
128
|
+
return this;
|
|
129
|
+
}
|
|
130
|
+
$defaultFn(fn) {
|
|
131
|
+
this.config.defaultFn = fn;
|
|
132
|
+
this.config.hasDefault = true;
|
|
133
|
+
return this;
|
|
134
|
+
}
|
|
135
|
+
$default = this.$defaultFn;
|
|
136
|
+
$onUpdateFn(fn) {
|
|
137
|
+
this.config.onUpdateFn = fn;
|
|
138
|
+
this.config.hasDefault = true;
|
|
139
|
+
return this;
|
|
140
|
+
}
|
|
141
|
+
$onUpdate = this.$onUpdateFn;
|
|
142
|
+
primaryKey() {
|
|
143
|
+
this.config.primaryKey = true;
|
|
144
|
+
this.config.notNull = true;
|
|
145
|
+
return this;
|
|
146
|
+
}
|
|
147
|
+
setName(name) {
|
|
148
|
+
if (this.config.name !== "")
|
|
149
|
+
return;
|
|
150
|
+
this.config.name = name;
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
// ../../../../node_modules/drizzle-orm/table.utils.js
|
|
156
|
+
var TableName;
|
|
157
|
+
var init_table_utils = __esm(() => {
|
|
158
|
+
TableName = Symbol.for("drizzle:Name");
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
// ../../../../node_modules/drizzle-orm/tracing-utils.js
|
|
162
|
+
function iife(fn, ...args) {
|
|
163
|
+
return fn(...args);
|
|
164
|
+
}
|
|
165
|
+
var init_tracing_utils = () => {};
|
|
166
|
+
|
|
167
|
+
// ../../../../node_modules/drizzle-orm/pg-core/unique-constraint.js
|
|
168
|
+
function uniqueKeyName(table, columns) {
|
|
169
|
+
return `${table[TableName]}_${columns.join("_")}_unique`;
|
|
170
|
+
}
|
|
171
|
+
var init_unique_constraint = __esm(() => {
|
|
172
|
+
init_table_utils();
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
// ../../../../node_modules/drizzle-orm/pg-core/columns/common.js
|
|
176
|
+
var PgColumn, ExtraConfigColumn;
|
|
177
|
+
var init_common = __esm(() => {
|
|
178
|
+
init_column();
|
|
179
|
+
init_entity();
|
|
180
|
+
init_unique_constraint();
|
|
181
|
+
PgColumn = class PgColumn extends Column {
|
|
182
|
+
constructor(table, config) {
|
|
183
|
+
if (!config.uniqueName) {
|
|
184
|
+
config.uniqueName = uniqueKeyName(table, [config.name]);
|
|
185
|
+
}
|
|
186
|
+
super(table, config);
|
|
187
|
+
this.table = table;
|
|
188
|
+
}
|
|
189
|
+
static [entityKind] = "PgColumn";
|
|
190
|
+
};
|
|
191
|
+
ExtraConfigColumn = class ExtraConfigColumn extends PgColumn {
|
|
192
|
+
static [entityKind] = "ExtraConfigColumn";
|
|
193
|
+
getSQLType() {
|
|
194
|
+
return this.getSQLType();
|
|
195
|
+
}
|
|
196
|
+
indexConfig = {
|
|
197
|
+
order: this.config.order ?? "asc",
|
|
198
|
+
nulls: this.config.nulls ?? "last",
|
|
199
|
+
opClass: this.config.opClass
|
|
200
|
+
};
|
|
201
|
+
defaultConfig = {
|
|
202
|
+
order: "asc",
|
|
203
|
+
nulls: "last",
|
|
204
|
+
opClass: undefined
|
|
205
|
+
};
|
|
206
|
+
asc() {
|
|
207
|
+
this.indexConfig.order = "asc";
|
|
208
|
+
return this;
|
|
209
|
+
}
|
|
210
|
+
desc() {
|
|
211
|
+
this.indexConfig.order = "desc";
|
|
212
|
+
return this;
|
|
213
|
+
}
|
|
214
|
+
nullsFirst() {
|
|
215
|
+
this.indexConfig.nulls = "first";
|
|
216
|
+
return this;
|
|
217
|
+
}
|
|
218
|
+
nullsLast() {
|
|
219
|
+
this.indexConfig.nulls = "last";
|
|
220
|
+
return this;
|
|
221
|
+
}
|
|
222
|
+
op(opClass) {
|
|
223
|
+
this.indexConfig.opClass = opClass;
|
|
224
|
+
return this;
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
// ../../../../node_modules/drizzle-orm/pg-core/columns/enum.js
|
|
230
|
+
function isPgEnum(obj) {
|
|
231
|
+
return !!obj && typeof obj === "function" && isPgEnumSym in obj && obj[isPgEnumSym] === true;
|
|
232
|
+
}
|
|
233
|
+
var PgEnumObjectColumn, isPgEnumSym, PgEnumColumn;
|
|
234
|
+
var init_enum = __esm(() => {
|
|
235
|
+
init_entity();
|
|
236
|
+
init_common();
|
|
237
|
+
PgEnumObjectColumn = class PgEnumObjectColumn extends PgColumn {
|
|
238
|
+
static [entityKind] = "PgEnumObjectColumn";
|
|
239
|
+
enum;
|
|
240
|
+
enumValues = this.config.enum.enumValues;
|
|
241
|
+
constructor(table, config) {
|
|
242
|
+
super(table, config);
|
|
243
|
+
this.enum = config.enum;
|
|
244
|
+
}
|
|
245
|
+
getSQLType() {
|
|
246
|
+
return this.enum.enumName;
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
isPgEnumSym = Symbol.for("drizzle:isPgEnum");
|
|
250
|
+
PgEnumColumn = class PgEnumColumn extends PgColumn {
|
|
251
|
+
static [entityKind] = "PgEnumColumn";
|
|
252
|
+
enum = this.config.enum;
|
|
253
|
+
enumValues = this.config.enum.enumValues;
|
|
254
|
+
constructor(table, config) {
|
|
255
|
+
super(table, config);
|
|
256
|
+
this.enum = config.enum;
|
|
257
|
+
}
|
|
258
|
+
getSQLType() {
|
|
259
|
+
return this.enum.enumName;
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
// ../../../../node_modules/drizzle-orm/subquery.js
|
|
265
|
+
var Subquery, WithSubquery;
|
|
266
|
+
var init_subquery = __esm(() => {
|
|
267
|
+
init_entity();
|
|
268
|
+
Subquery = class Subquery {
|
|
269
|
+
static [entityKind] = "Subquery";
|
|
270
|
+
constructor(sql, fields, alias, isWith = false, usedTables = []) {
|
|
271
|
+
this._ = {
|
|
272
|
+
brand: "Subquery",
|
|
273
|
+
sql,
|
|
274
|
+
selectedFields: fields,
|
|
275
|
+
alias,
|
|
276
|
+
isWith,
|
|
277
|
+
usedTables
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
};
|
|
281
|
+
WithSubquery = class WithSubquery extends Subquery {
|
|
282
|
+
static [entityKind] = "WithSubquery";
|
|
283
|
+
};
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
// ../../../../node_modules/drizzle-orm/version.js
|
|
287
|
+
var version = "0.45.1";
|
|
288
|
+
var init_version = () => {};
|
|
289
|
+
|
|
290
|
+
// ../../../../node_modules/drizzle-orm/tracing.js
|
|
291
|
+
var otel, rawTracer, tracer;
|
|
292
|
+
var init_tracing = __esm(() => {
|
|
293
|
+
init_tracing_utils();
|
|
294
|
+
init_version();
|
|
295
|
+
tracer = {
|
|
296
|
+
startActiveSpan(name, fn) {
|
|
297
|
+
if (!otel) {
|
|
298
|
+
return fn();
|
|
299
|
+
}
|
|
300
|
+
if (!rawTracer) {
|
|
301
|
+
rawTracer = otel.trace.getTracer("drizzle-orm", version);
|
|
302
|
+
}
|
|
303
|
+
return iife((otel2, rawTracer2) => rawTracer2.startActiveSpan(name, (span) => {
|
|
304
|
+
try {
|
|
305
|
+
return fn(span);
|
|
306
|
+
} catch (e) {
|
|
307
|
+
span.setStatus({
|
|
308
|
+
code: otel2.SpanStatusCode.ERROR,
|
|
309
|
+
message: e instanceof Error ? e.message : "Unknown error"
|
|
310
|
+
});
|
|
311
|
+
throw e;
|
|
312
|
+
} finally {
|
|
313
|
+
span.end();
|
|
314
|
+
}
|
|
315
|
+
}), otel, rawTracer);
|
|
316
|
+
}
|
|
317
|
+
};
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
// ../../../../node_modules/drizzle-orm/view-common.js
|
|
321
|
+
var ViewBaseConfig;
|
|
322
|
+
var init_view_common = __esm(() => {
|
|
323
|
+
ViewBaseConfig = Symbol.for("drizzle:ViewBaseConfig");
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
// ../../../../node_modules/drizzle-orm/table.js
|
|
327
|
+
function isTable(table) {
|
|
328
|
+
return typeof table === "object" && table !== null && IsDrizzleTable in table;
|
|
329
|
+
}
|
|
330
|
+
function getTableName(table) {
|
|
331
|
+
return table[TableName];
|
|
332
|
+
}
|
|
333
|
+
function getTableUniqueName(table) {
|
|
334
|
+
return `${table[Schema] ?? "public"}.${table[TableName]}`;
|
|
335
|
+
}
|
|
336
|
+
var Schema, Columns, ExtraConfigColumns, OriginalName, BaseName, IsAlias, ExtraConfigBuilder, IsDrizzleTable, Table;
|
|
337
|
+
var init_table = __esm(() => {
|
|
338
|
+
init_entity();
|
|
339
|
+
init_table_utils();
|
|
340
|
+
Schema = Symbol.for("drizzle:Schema");
|
|
341
|
+
Columns = Symbol.for("drizzle:Columns");
|
|
342
|
+
ExtraConfigColumns = Symbol.for("drizzle:ExtraConfigColumns");
|
|
343
|
+
OriginalName = Symbol.for("drizzle:OriginalName");
|
|
344
|
+
BaseName = Symbol.for("drizzle:BaseName");
|
|
345
|
+
IsAlias = Symbol.for("drizzle:IsAlias");
|
|
346
|
+
ExtraConfigBuilder = Symbol.for("drizzle:ExtraConfigBuilder");
|
|
347
|
+
IsDrizzleTable = Symbol.for("drizzle:IsDrizzleTable");
|
|
348
|
+
Table = class Table {
|
|
349
|
+
static [entityKind] = "Table";
|
|
350
|
+
static Symbol = {
|
|
351
|
+
Name: TableName,
|
|
352
|
+
Schema,
|
|
353
|
+
OriginalName,
|
|
354
|
+
Columns,
|
|
355
|
+
ExtraConfigColumns,
|
|
356
|
+
BaseName,
|
|
357
|
+
IsAlias,
|
|
358
|
+
ExtraConfigBuilder
|
|
359
|
+
};
|
|
360
|
+
[TableName];
|
|
361
|
+
[OriginalName];
|
|
362
|
+
[Schema];
|
|
363
|
+
[Columns];
|
|
364
|
+
[ExtraConfigColumns];
|
|
365
|
+
[BaseName];
|
|
366
|
+
[IsAlias] = false;
|
|
367
|
+
[IsDrizzleTable] = true;
|
|
368
|
+
[ExtraConfigBuilder] = undefined;
|
|
369
|
+
constructor(name, schema, baseName) {
|
|
370
|
+
this[TableName] = this[OriginalName] = name;
|
|
371
|
+
this[Schema] = schema;
|
|
372
|
+
this[BaseName] = baseName;
|
|
373
|
+
}
|
|
374
|
+
};
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
// ../../../../node_modules/drizzle-orm/sql/sql.js
|
|
378
|
+
function isSQLWrapper(value) {
|
|
379
|
+
return value !== null && value !== undefined && typeof value.getSQL === "function";
|
|
380
|
+
}
|
|
381
|
+
function mergeQueries(queries) {
|
|
382
|
+
const result = { sql: "", params: [] };
|
|
383
|
+
for (const query of queries) {
|
|
384
|
+
result.sql += query.sql;
|
|
385
|
+
result.params.push(...query.params);
|
|
386
|
+
if (query.typings?.length) {
|
|
387
|
+
if (!result.typings) {
|
|
388
|
+
result.typings = [];
|
|
389
|
+
}
|
|
390
|
+
result.typings.push(...query.typings);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
return result;
|
|
394
|
+
}
|
|
395
|
+
function name(value) {
|
|
396
|
+
return new Name(value);
|
|
397
|
+
}
|
|
398
|
+
function isDriverValueEncoder(value) {
|
|
399
|
+
return typeof value === "object" && value !== null && "mapToDriverValue" in value && typeof value.mapToDriverValue === "function";
|
|
400
|
+
}
|
|
401
|
+
function param(value, encoder) {
|
|
402
|
+
return new Param(value, encoder);
|
|
403
|
+
}
|
|
404
|
+
function sql(strings, ...params) {
|
|
405
|
+
const queryChunks = [];
|
|
406
|
+
if (params.length > 0 || strings.length > 0 && strings[0] !== "") {
|
|
407
|
+
queryChunks.push(new StringChunk(strings[0]));
|
|
408
|
+
}
|
|
409
|
+
for (const [paramIndex, param2] of params.entries()) {
|
|
410
|
+
queryChunks.push(param2, new StringChunk(strings[paramIndex + 1]));
|
|
411
|
+
}
|
|
412
|
+
return new SQL(queryChunks);
|
|
413
|
+
}
|
|
414
|
+
function placeholder(name2) {
|
|
415
|
+
return new Placeholder(name2);
|
|
416
|
+
}
|
|
417
|
+
function fillPlaceholders(params, values) {
|
|
418
|
+
return params.map((p) => {
|
|
419
|
+
if (is(p, Placeholder)) {
|
|
420
|
+
if (!(p.name in values)) {
|
|
421
|
+
throw new Error(`No value for placeholder "${p.name}" was provided`);
|
|
422
|
+
}
|
|
423
|
+
return values[p.name];
|
|
424
|
+
}
|
|
425
|
+
if (is(p, Param) && is(p.value, Placeholder)) {
|
|
426
|
+
if (!(p.value.name in values)) {
|
|
427
|
+
throw new Error(`No value for placeholder "${p.value.name}" was provided`);
|
|
428
|
+
}
|
|
429
|
+
return p.encoder.mapToDriverValue(values[p.value.name]);
|
|
430
|
+
}
|
|
431
|
+
return p;
|
|
432
|
+
});
|
|
433
|
+
}
|
|
434
|
+
function isView(view) {
|
|
435
|
+
return typeof view === "object" && view !== null && IsDrizzleView in view;
|
|
436
|
+
}
|
|
437
|
+
function getViewName(view) {
|
|
438
|
+
return view[ViewBaseConfig].name;
|
|
439
|
+
}
|
|
440
|
+
var FakePrimitiveParam, StringChunk, SQL, Name, noopDecoder, noopEncoder, noopMapper, Param, Placeholder, IsDrizzleView, View;
|
|
441
|
+
var init_sql = __esm(() => {
|
|
442
|
+
init_entity();
|
|
443
|
+
init_enum();
|
|
444
|
+
init_subquery();
|
|
445
|
+
init_tracing();
|
|
446
|
+
init_view_common();
|
|
447
|
+
init_column();
|
|
448
|
+
init_table();
|
|
449
|
+
FakePrimitiveParam = class FakePrimitiveParam {
|
|
450
|
+
static [entityKind] = "FakePrimitiveParam";
|
|
451
|
+
};
|
|
452
|
+
StringChunk = class StringChunk {
|
|
453
|
+
static [entityKind] = "StringChunk";
|
|
454
|
+
value;
|
|
455
|
+
constructor(value) {
|
|
456
|
+
this.value = Array.isArray(value) ? value : [value];
|
|
457
|
+
}
|
|
458
|
+
getSQL() {
|
|
459
|
+
return new SQL([this]);
|
|
460
|
+
}
|
|
461
|
+
};
|
|
462
|
+
SQL = class SQL {
|
|
463
|
+
constructor(queryChunks) {
|
|
464
|
+
this.queryChunks = queryChunks;
|
|
465
|
+
for (const chunk of queryChunks) {
|
|
466
|
+
if (is(chunk, Table)) {
|
|
467
|
+
const schemaName = chunk[Table.Symbol.Schema];
|
|
468
|
+
this.usedTables.push(schemaName === undefined ? chunk[Table.Symbol.Name] : schemaName + "." + chunk[Table.Symbol.Name]);
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
static [entityKind] = "SQL";
|
|
473
|
+
decoder = noopDecoder;
|
|
474
|
+
shouldInlineParams = false;
|
|
475
|
+
usedTables = [];
|
|
476
|
+
append(query) {
|
|
477
|
+
this.queryChunks.push(...query.queryChunks);
|
|
478
|
+
return this;
|
|
479
|
+
}
|
|
480
|
+
toQuery(config) {
|
|
481
|
+
return tracer.startActiveSpan("drizzle.buildSQL", (span) => {
|
|
482
|
+
const query = this.buildQueryFromSourceParams(this.queryChunks, config);
|
|
483
|
+
span?.setAttributes({
|
|
484
|
+
"drizzle.query.text": query.sql,
|
|
485
|
+
"drizzle.query.params": JSON.stringify(query.params)
|
|
486
|
+
});
|
|
487
|
+
return query;
|
|
488
|
+
});
|
|
489
|
+
}
|
|
490
|
+
buildQueryFromSourceParams(chunks, _config) {
|
|
491
|
+
const config = Object.assign({}, _config, {
|
|
492
|
+
inlineParams: _config.inlineParams || this.shouldInlineParams,
|
|
493
|
+
paramStartIndex: _config.paramStartIndex || { value: 0 }
|
|
494
|
+
});
|
|
495
|
+
const {
|
|
496
|
+
casing,
|
|
497
|
+
escapeName,
|
|
498
|
+
escapeParam,
|
|
499
|
+
prepareTyping,
|
|
500
|
+
inlineParams,
|
|
501
|
+
paramStartIndex
|
|
502
|
+
} = config;
|
|
503
|
+
return mergeQueries(chunks.map((chunk) => {
|
|
504
|
+
if (is(chunk, StringChunk)) {
|
|
505
|
+
return { sql: chunk.value.join(""), params: [] };
|
|
506
|
+
}
|
|
507
|
+
if (is(chunk, Name)) {
|
|
508
|
+
return { sql: escapeName(chunk.value), params: [] };
|
|
509
|
+
}
|
|
510
|
+
if (chunk === undefined) {
|
|
511
|
+
return { sql: "", params: [] };
|
|
512
|
+
}
|
|
513
|
+
if (Array.isArray(chunk)) {
|
|
514
|
+
const result = [new StringChunk("(")];
|
|
515
|
+
for (const [i, p] of chunk.entries()) {
|
|
516
|
+
result.push(p);
|
|
517
|
+
if (i < chunk.length - 1) {
|
|
518
|
+
result.push(new StringChunk(", "));
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
result.push(new StringChunk(")"));
|
|
522
|
+
return this.buildQueryFromSourceParams(result, config);
|
|
523
|
+
}
|
|
524
|
+
if (is(chunk, SQL)) {
|
|
525
|
+
return this.buildQueryFromSourceParams(chunk.queryChunks, {
|
|
526
|
+
...config,
|
|
527
|
+
inlineParams: inlineParams || chunk.shouldInlineParams
|
|
528
|
+
});
|
|
529
|
+
}
|
|
530
|
+
if (is(chunk, Table)) {
|
|
531
|
+
const schemaName = chunk[Table.Symbol.Schema];
|
|
532
|
+
const tableName = chunk[Table.Symbol.Name];
|
|
533
|
+
return {
|
|
534
|
+
sql: schemaName === undefined || chunk[IsAlias] ? escapeName(tableName) : escapeName(schemaName) + "." + escapeName(tableName),
|
|
535
|
+
params: []
|
|
536
|
+
};
|
|
537
|
+
}
|
|
538
|
+
if (is(chunk, Column)) {
|
|
539
|
+
const columnName = casing.getColumnCasing(chunk);
|
|
540
|
+
if (_config.invokeSource === "indexes") {
|
|
541
|
+
return { sql: escapeName(columnName), params: [] };
|
|
542
|
+
}
|
|
543
|
+
const schemaName = chunk.table[Table.Symbol.Schema];
|
|
544
|
+
return {
|
|
545
|
+
sql: chunk.table[IsAlias] || schemaName === undefined ? escapeName(chunk.table[Table.Symbol.Name]) + "." + escapeName(columnName) : escapeName(schemaName) + "." + escapeName(chunk.table[Table.Symbol.Name]) + "." + escapeName(columnName),
|
|
546
|
+
params: []
|
|
547
|
+
};
|
|
548
|
+
}
|
|
549
|
+
if (is(chunk, View)) {
|
|
550
|
+
const schemaName = chunk[ViewBaseConfig].schema;
|
|
551
|
+
const viewName = chunk[ViewBaseConfig].name;
|
|
552
|
+
return {
|
|
553
|
+
sql: schemaName === undefined || chunk[ViewBaseConfig].isAlias ? escapeName(viewName) : escapeName(schemaName) + "." + escapeName(viewName),
|
|
554
|
+
params: []
|
|
555
|
+
};
|
|
556
|
+
}
|
|
557
|
+
if (is(chunk, Param)) {
|
|
558
|
+
if (is(chunk.value, Placeholder)) {
|
|
559
|
+
return { sql: escapeParam(paramStartIndex.value++, chunk), params: [chunk], typings: ["none"] };
|
|
560
|
+
}
|
|
561
|
+
const mappedValue = chunk.value === null ? null : chunk.encoder.mapToDriverValue(chunk.value);
|
|
562
|
+
if (is(mappedValue, SQL)) {
|
|
563
|
+
return this.buildQueryFromSourceParams([mappedValue], config);
|
|
564
|
+
}
|
|
565
|
+
if (inlineParams) {
|
|
566
|
+
return { sql: this.mapInlineParam(mappedValue, config), params: [] };
|
|
567
|
+
}
|
|
568
|
+
let typings = ["none"];
|
|
569
|
+
if (prepareTyping) {
|
|
570
|
+
typings = [prepareTyping(chunk.encoder)];
|
|
571
|
+
}
|
|
572
|
+
return { sql: escapeParam(paramStartIndex.value++, mappedValue), params: [mappedValue], typings };
|
|
573
|
+
}
|
|
574
|
+
if (is(chunk, Placeholder)) {
|
|
575
|
+
return { sql: escapeParam(paramStartIndex.value++, chunk), params: [chunk], typings: ["none"] };
|
|
576
|
+
}
|
|
577
|
+
if (is(chunk, SQL.Aliased) && chunk.fieldAlias !== undefined) {
|
|
578
|
+
return { sql: escapeName(chunk.fieldAlias), params: [] };
|
|
579
|
+
}
|
|
580
|
+
if (is(chunk, Subquery)) {
|
|
581
|
+
if (chunk._.isWith) {
|
|
582
|
+
return { sql: escapeName(chunk._.alias), params: [] };
|
|
583
|
+
}
|
|
584
|
+
return this.buildQueryFromSourceParams([
|
|
585
|
+
new StringChunk("("),
|
|
586
|
+
chunk._.sql,
|
|
587
|
+
new StringChunk(") "),
|
|
588
|
+
new Name(chunk._.alias)
|
|
589
|
+
], config);
|
|
590
|
+
}
|
|
591
|
+
if (isPgEnum(chunk)) {
|
|
592
|
+
if (chunk.schema) {
|
|
593
|
+
return { sql: escapeName(chunk.schema) + "." + escapeName(chunk.enumName), params: [] };
|
|
594
|
+
}
|
|
595
|
+
return { sql: escapeName(chunk.enumName), params: [] };
|
|
596
|
+
}
|
|
597
|
+
if (isSQLWrapper(chunk)) {
|
|
598
|
+
if (chunk.shouldOmitSQLParens?.()) {
|
|
599
|
+
return this.buildQueryFromSourceParams([chunk.getSQL()], config);
|
|
600
|
+
}
|
|
601
|
+
return this.buildQueryFromSourceParams([
|
|
602
|
+
new StringChunk("("),
|
|
603
|
+
chunk.getSQL(),
|
|
604
|
+
new StringChunk(")")
|
|
605
|
+
], config);
|
|
606
|
+
}
|
|
607
|
+
if (inlineParams) {
|
|
608
|
+
return { sql: this.mapInlineParam(chunk, config), params: [] };
|
|
609
|
+
}
|
|
610
|
+
return { sql: escapeParam(paramStartIndex.value++, chunk), params: [chunk], typings: ["none"] };
|
|
611
|
+
}));
|
|
612
|
+
}
|
|
613
|
+
mapInlineParam(chunk, { escapeString }) {
|
|
614
|
+
if (chunk === null) {
|
|
615
|
+
return "null";
|
|
616
|
+
}
|
|
617
|
+
if (typeof chunk === "number" || typeof chunk === "boolean") {
|
|
618
|
+
return chunk.toString();
|
|
619
|
+
}
|
|
620
|
+
if (typeof chunk === "string") {
|
|
621
|
+
return escapeString(chunk);
|
|
622
|
+
}
|
|
623
|
+
if (typeof chunk === "object") {
|
|
624
|
+
const mappedValueAsString = chunk.toString();
|
|
625
|
+
if (mappedValueAsString === "[object Object]") {
|
|
626
|
+
return escapeString(JSON.stringify(chunk));
|
|
627
|
+
}
|
|
628
|
+
return escapeString(mappedValueAsString);
|
|
629
|
+
}
|
|
630
|
+
throw new Error("Unexpected param value: " + chunk);
|
|
631
|
+
}
|
|
632
|
+
getSQL() {
|
|
633
|
+
return this;
|
|
634
|
+
}
|
|
635
|
+
as(alias) {
|
|
636
|
+
if (alias === undefined) {
|
|
637
|
+
return this;
|
|
638
|
+
}
|
|
639
|
+
return new SQL.Aliased(this, alias);
|
|
640
|
+
}
|
|
641
|
+
mapWith(decoder) {
|
|
642
|
+
this.decoder = typeof decoder === "function" ? { mapFromDriverValue: decoder } : decoder;
|
|
643
|
+
return this;
|
|
644
|
+
}
|
|
645
|
+
inlineParams() {
|
|
646
|
+
this.shouldInlineParams = true;
|
|
647
|
+
return this;
|
|
648
|
+
}
|
|
649
|
+
if(condition) {
|
|
650
|
+
return condition ? this : undefined;
|
|
651
|
+
}
|
|
652
|
+
};
|
|
653
|
+
Name = class Name {
|
|
654
|
+
constructor(value) {
|
|
655
|
+
this.value = value;
|
|
656
|
+
}
|
|
657
|
+
static [entityKind] = "Name";
|
|
658
|
+
brand;
|
|
659
|
+
getSQL() {
|
|
660
|
+
return new SQL([this]);
|
|
661
|
+
}
|
|
662
|
+
};
|
|
663
|
+
noopDecoder = {
|
|
664
|
+
mapFromDriverValue: (value) => value
|
|
665
|
+
};
|
|
666
|
+
noopEncoder = {
|
|
667
|
+
mapToDriverValue: (value) => value
|
|
668
|
+
};
|
|
669
|
+
noopMapper = {
|
|
670
|
+
...noopDecoder,
|
|
671
|
+
...noopEncoder
|
|
672
|
+
};
|
|
673
|
+
Param = class Param {
|
|
674
|
+
constructor(value, encoder = noopEncoder) {
|
|
675
|
+
this.value = value;
|
|
676
|
+
this.encoder = encoder;
|
|
677
|
+
}
|
|
678
|
+
static [entityKind] = "Param";
|
|
679
|
+
brand;
|
|
680
|
+
getSQL() {
|
|
681
|
+
return new SQL([this]);
|
|
682
|
+
}
|
|
683
|
+
};
|
|
684
|
+
((sql2) => {
|
|
685
|
+
function empty() {
|
|
686
|
+
return new SQL([]);
|
|
687
|
+
}
|
|
688
|
+
sql2.empty = empty;
|
|
689
|
+
function fromList(list) {
|
|
690
|
+
return new SQL(list);
|
|
691
|
+
}
|
|
692
|
+
sql2.fromList = fromList;
|
|
693
|
+
function raw(str) {
|
|
694
|
+
return new SQL([new StringChunk(str)]);
|
|
695
|
+
}
|
|
696
|
+
sql2.raw = raw;
|
|
697
|
+
function join(chunks, separator) {
|
|
698
|
+
const result = [];
|
|
699
|
+
for (const [i, chunk] of chunks.entries()) {
|
|
700
|
+
if (i > 0 && separator !== undefined) {
|
|
701
|
+
result.push(separator);
|
|
702
|
+
}
|
|
703
|
+
result.push(chunk);
|
|
704
|
+
}
|
|
705
|
+
return new SQL(result);
|
|
706
|
+
}
|
|
707
|
+
sql2.join = join;
|
|
708
|
+
function identifier(value) {
|
|
709
|
+
return new Name(value);
|
|
710
|
+
}
|
|
711
|
+
sql2.identifier = identifier;
|
|
712
|
+
function placeholder2(name2) {
|
|
713
|
+
return new Placeholder(name2);
|
|
714
|
+
}
|
|
715
|
+
sql2.placeholder = placeholder2;
|
|
716
|
+
function param2(value, encoder) {
|
|
717
|
+
return new Param(value, encoder);
|
|
718
|
+
}
|
|
719
|
+
sql2.param = param2;
|
|
720
|
+
})(sql || (sql = {}));
|
|
721
|
+
((SQL2) => {
|
|
722
|
+
|
|
723
|
+
class Aliased {
|
|
724
|
+
constructor(sql2, fieldAlias) {
|
|
725
|
+
this.sql = sql2;
|
|
726
|
+
this.fieldAlias = fieldAlias;
|
|
727
|
+
}
|
|
728
|
+
static [entityKind] = "SQL.Aliased";
|
|
729
|
+
isSelectionField = false;
|
|
730
|
+
getSQL() {
|
|
731
|
+
return this.sql;
|
|
732
|
+
}
|
|
733
|
+
clone() {
|
|
734
|
+
return new Aliased(this.sql, this.fieldAlias);
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
SQL2.Aliased = Aliased;
|
|
738
|
+
})(SQL || (SQL = {}));
|
|
739
|
+
Placeholder = class Placeholder {
|
|
740
|
+
constructor(name2) {
|
|
741
|
+
this.name = name2;
|
|
742
|
+
}
|
|
743
|
+
static [entityKind] = "Placeholder";
|
|
744
|
+
getSQL() {
|
|
745
|
+
return new SQL([this]);
|
|
746
|
+
}
|
|
747
|
+
};
|
|
748
|
+
IsDrizzleView = Symbol.for("drizzle:IsDrizzleView");
|
|
749
|
+
View = class View {
|
|
750
|
+
static [entityKind] = "View";
|
|
751
|
+
[ViewBaseConfig];
|
|
752
|
+
[IsDrizzleView] = true;
|
|
753
|
+
constructor({ name: name2, schema, selectedFields, query }) {
|
|
754
|
+
this[ViewBaseConfig] = {
|
|
755
|
+
name: name2,
|
|
756
|
+
originalName: name2,
|
|
757
|
+
schema,
|
|
758
|
+
selectedFields,
|
|
759
|
+
query,
|
|
760
|
+
isExisting: !query,
|
|
761
|
+
isAlias: false
|
|
762
|
+
};
|
|
763
|
+
}
|
|
764
|
+
getSQL() {
|
|
765
|
+
return new SQL([this]);
|
|
766
|
+
}
|
|
767
|
+
};
|
|
768
|
+
Column.prototype.getSQL = function() {
|
|
769
|
+
return new SQL([this]);
|
|
770
|
+
};
|
|
771
|
+
Table.prototype.getSQL = function() {
|
|
772
|
+
return new SQL([this]);
|
|
773
|
+
};
|
|
774
|
+
Subquery.prototype.getSQL = function() {
|
|
775
|
+
return new SQL([this]);
|
|
776
|
+
};
|
|
777
|
+
});
|
|
778
|
+
|
|
779
|
+
// ../../../../node_modules/drizzle-orm/alias.js
|
|
780
|
+
function aliasedTable(table, tableAlias) {
|
|
781
|
+
return new Proxy(table, new TableAliasProxyHandler(tableAlias, false));
|
|
782
|
+
}
|
|
783
|
+
function aliasedRelation(relation, tableAlias) {
|
|
784
|
+
return new Proxy(relation, new RelationTableAliasProxyHandler(tableAlias));
|
|
785
|
+
}
|
|
786
|
+
function aliasedTableColumn(column, tableAlias) {
|
|
787
|
+
return new Proxy(column, new ColumnAliasProxyHandler(new Proxy(column.table, new TableAliasProxyHandler(tableAlias, false))));
|
|
788
|
+
}
|
|
789
|
+
function mapColumnsInAliasedSQLToAlias(query, alias) {
|
|
790
|
+
return new SQL.Aliased(mapColumnsInSQLToAlias(query.sql, alias), query.fieldAlias);
|
|
791
|
+
}
|
|
792
|
+
function mapColumnsInSQLToAlias(query, alias) {
|
|
793
|
+
return sql.join(query.queryChunks.map((c) => {
|
|
794
|
+
if (is(c, Column)) {
|
|
795
|
+
return aliasedTableColumn(c, alias);
|
|
796
|
+
}
|
|
797
|
+
if (is(c, SQL)) {
|
|
798
|
+
return mapColumnsInSQLToAlias(c, alias);
|
|
799
|
+
}
|
|
800
|
+
if (is(c, SQL.Aliased)) {
|
|
801
|
+
return mapColumnsInAliasedSQLToAlias(c, alias);
|
|
802
|
+
}
|
|
803
|
+
return c;
|
|
804
|
+
}));
|
|
805
|
+
}
|
|
806
|
+
var ColumnAliasProxyHandler, TableAliasProxyHandler, RelationTableAliasProxyHandler;
|
|
807
|
+
var init_alias = __esm(() => {
|
|
808
|
+
init_column();
|
|
809
|
+
init_entity();
|
|
810
|
+
init_sql();
|
|
811
|
+
init_table();
|
|
812
|
+
init_view_common();
|
|
813
|
+
ColumnAliasProxyHandler = class ColumnAliasProxyHandler {
|
|
814
|
+
constructor(table) {
|
|
815
|
+
this.table = table;
|
|
816
|
+
}
|
|
817
|
+
static [entityKind] = "ColumnAliasProxyHandler";
|
|
818
|
+
get(columnObj, prop) {
|
|
819
|
+
if (prop === "table") {
|
|
820
|
+
return this.table;
|
|
821
|
+
}
|
|
822
|
+
return columnObj[prop];
|
|
823
|
+
}
|
|
824
|
+
};
|
|
825
|
+
TableAliasProxyHandler = class TableAliasProxyHandler {
|
|
826
|
+
constructor(alias, replaceOriginalName) {
|
|
827
|
+
this.alias = alias;
|
|
828
|
+
this.replaceOriginalName = replaceOriginalName;
|
|
829
|
+
}
|
|
830
|
+
static [entityKind] = "TableAliasProxyHandler";
|
|
831
|
+
get(target, prop) {
|
|
832
|
+
if (prop === Table.Symbol.IsAlias) {
|
|
833
|
+
return true;
|
|
834
|
+
}
|
|
835
|
+
if (prop === Table.Symbol.Name) {
|
|
836
|
+
return this.alias;
|
|
837
|
+
}
|
|
838
|
+
if (this.replaceOriginalName && prop === Table.Symbol.OriginalName) {
|
|
839
|
+
return this.alias;
|
|
840
|
+
}
|
|
841
|
+
if (prop === ViewBaseConfig) {
|
|
842
|
+
return {
|
|
843
|
+
...target[ViewBaseConfig],
|
|
844
|
+
name: this.alias,
|
|
845
|
+
isAlias: true
|
|
846
|
+
};
|
|
847
|
+
}
|
|
848
|
+
if (prop === Table.Symbol.Columns) {
|
|
849
|
+
const columns = target[Table.Symbol.Columns];
|
|
850
|
+
if (!columns) {
|
|
851
|
+
return columns;
|
|
852
|
+
}
|
|
853
|
+
const proxiedColumns = {};
|
|
854
|
+
Object.keys(columns).map((key) => {
|
|
855
|
+
proxiedColumns[key] = new Proxy(columns[key], new ColumnAliasProxyHandler(new Proxy(target, this)));
|
|
856
|
+
});
|
|
857
|
+
return proxiedColumns;
|
|
858
|
+
}
|
|
859
|
+
const value = target[prop];
|
|
860
|
+
if (is(value, Column)) {
|
|
861
|
+
return new Proxy(value, new ColumnAliasProxyHandler(new Proxy(target, this)));
|
|
862
|
+
}
|
|
863
|
+
return value;
|
|
864
|
+
}
|
|
865
|
+
};
|
|
866
|
+
RelationTableAliasProxyHandler = class RelationTableAliasProxyHandler {
|
|
867
|
+
constructor(alias) {
|
|
868
|
+
this.alias = alias;
|
|
869
|
+
}
|
|
870
|
+
static [entityKind] = "RelationTableAliasProxyHandler";
|
|
871
|
+
get(target, prop) {
|
|
872
|
+
if (prop === "sourceTable") {
|
|
873
|
+
return aliasedTable(target.sourceTable, this.alias);
|
|
874
|
+
}
|
|
875
|
+
return target[prop];
|
|
876
|
+
}
|
|
877
|
+
};
|
|
878
|
+
});
|
|
879
|
+
|
|
880
|
+
// ../../../../node_modules/drizzle-orm/errors.js
|
|
881
|
+
var DrizzleError, DrizzleQueryError, TransactionRollbackError;
|
|
882
|
+
var init_errors = __esm(() => {
|
|
883
|
+
init_entity();
|
|
884
|
+
DrizzleError = class DrizzleError extends Error {
|
|
885
|
+
static [entityKind] = "DrizzleError";
|
|
886
|
+
constructor({ message, cause }) {
|
|
887
|
+
super(message);
|
|
888
|
+
this.name = "DrizzleError";
|
|
889
|
+
this.cause = cause;
|
|
890
|
+
}
|
|
891
|
+
};
|
|
892
|
+
DrizzleQueryError = class DrizzleQueryError extends Error {
|
|
893
|
+
constructor(query, params, cause) {
|
|
894
|
+
super(`Failed query: ${query}
|
|
895
|
+
params: ${params}`);
|
|
896
|
+
this.query = query;
|
|
897
|
+
this.params = params;
|
|
898
|
+
this.cause = cause;
|
|
899
|
+
Error.captureStackTrace(this, DrizzleQueryError);
|
|
900
|
+
if (cause)
|
|
901
|
+
this.cause = cause;
|
|
902
|
+
}
|
|
903
|
+
};
|
|
904
|
+
TransactionRollbackError = class TransactionRollbackError extends DrizzleError {
|
|
905
|
+
static [entityKind] = "TransactionRollbackError";
|
|
906
|
+
constructor() {
|
|
907
|
+
super({ message: "Rollback" });
|
|
908
|
+
}
|
|
909
|
+
};
|
|
910
|
+
});
|
|
911
|
+
|
|
912
|
+
// ../../../../node_modules/drizzle-orm/logger.js
|
|
913
|
+
var ConsoleLogWriter, DefaultLogger, NoopLogger;
|
|
914
|
+
var init_logger = __esm(() => {
|
|
915
|
+
init_entity();
|
|
916
|
+
ConsoleLogWriter = class ConsoleLogWriter {
|
|
917
|
+
static [entityKind] = "ConsoleLogWriter";
|
|
918
|
+
write(message) {
|
|
919
|
+
console.log(message);
|
|
920
|
+
}
|
|
921
|
+
};
|
|
922
|
+
DefaultLogger = class DefaultLogger {
|
|
923
|
+
static [entityKind] = "DefaultLogger";
|
|
924
|
+
writer;
|
|
925
|
+
constructor(config) {
|
|
926
|
+
this.writer = config?.writer ?? new ConsoleLogWriter;
|
|
927
|
+
}
|
|
928
|
+
logQuery(query, params) {
|
|
929
|
+
const stringifiedParams = params.map((p) => {
|
|
930
|
+
try {
|
|
931
|
+
return JSON.stringify(p);
|
|
932
|
+
} catch {
|
|
933
|
+
return String(p);
|
|
934
|
+
}
|
|
935
|
+
});
|
|
936
|
+
const paramsStr = stringifiedParams.length ? ` -- params: [${stringifiedParams.join(", ")}]` : "";
|
|
937
|
+
this.writer.write(`Query: ${query}${paramsStr}`);
|
|
938
|
+
}
|
|
939
|
+
};
|
|
940
|
+
NoopLogger = class NoopLogger {
|
|
941
|
+
static [entityKind] = "NoopLogger";
|
|
942
|
+
logQuery() {}
|
|
943
|
+
};
|
|
944
|
+
});
|
|
945
|
+
|
|
946
|
+
// ../../../../node_modules/drizzle-orm/query-promise.js
|
|
947
|
+
var QueryPromise;
|
|
948
|
+
var init_query_promise = __esm(() => {
|
|
949
|
+
init_entity();
|
|
950
|
+
QueryPromise = class QueryPromise {
|
|
951
|
+
static [entityKind] = "QueryPromise";
|
|
952
|
+
[Symbol.toStringTag] = "QueryPromise";
|
|
953
|
+
catch(onRejected) {
|
|
954
|
+
return this.then(undefined, onRejected);
|
|
955
|
+
}
|
|
956
|
+
finally(onFinally) {
|
|
957
|
+
return this.then((value) => {
|
|
958
|
+
onFinally?.();
|
|
959
|
+
return value;
|
|
960
|
+
}, (reason) => {
|
|
961
|
+
onFinally?.();
|
|
962
|
+
throw reason;
|
|
963
|
+
});
|
|
964
|
+
}
|
|
965
|
+
then(onFulfilled, onRejected) {
|
|
966
|
+
return this.execute().then(onFulfilled, onRejected);
|
|
967
|
+
}
|
|
968
|
+
};
|
|
969
|
+
});
|
|
970
|
+
|
|
971
|
+
// ../../../../node_modules/drizzle-orm/utils.js
|
|
972
|
+
function mapResultRow(columns, row, joinsNotNullableMap) {
|
|
973
|
+
const nullifyMap = {};
|
|
974
|
+
const result = columns.reduce((result2, { path, field }, columnIndex) => {
|
|
975
|
+
let decoder;
|
|
976
|
+
if (is(field, Column)) {
|
|
977
|
+
decoder = field;
|
|
978
|
+
} else if (is(field, SQL)) {
|
|
979
|
+
decoder = field.decoder;
|
|
980
|
+
} else if (is(field, Subquery)) {
|
|
981
|
+
decoder = field._.sql.decoder;
|
|
982
|
+
} else {
|
|
983
|
+
decoder = field.sql.decoder;
|
|
984
|
+
}
|
|
985
|
+
let node = result2;
|
|
986
|
+
for (const [pathChunkIndex, pathChunk] of path.entries()) {
|
|
987
|
+
if (pathChunkIndex < path.length - 1) {
|
|
988
|
+
if (!(pathChunk in node)) {
|
|
989
|
+
node[pathChunk] = {};
|
|
990
|
+
}
|
|
991
|
+
node = node[pathChunk];
|
|
992
|
+
} else {
|
|
993
|
+
const rawValue = row[columnIndex];
|
|
994
|
+
const value = node[pathChunk] = rawValue === null ? null : decoder.mapFromDriverValue(rawValue);
|
|
995
|
+
if (joinsNotNullableMap && is(field, Column) && path.length === 2) {
|
|
996
|
+
const objectName = path[0];
|
|
997
|
+
if (!(objectName in nullifyMap)) {
|
|
998
|
+
nullifyMap[objectName] = value === null ? getTableName(field.table) : false;
|
|
999
|
+
} else if (typeof nullifyMap[objectName] === "string" && nullifyMap[objectName] !== getTableName(field.table)) {
|
|
1000
|
+
nullifyMap[objectName] = false;
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
return result2;
|
|
1006
|
+
}, {});
|
|
1007
|
+
if (joinsNotNullableMap && Object.keys(nullifyMap).length > 0) {
|
|
1008
|
+
for (const [objectName, tableName] of Object.entries(nullifyMap)) {
|
|
1009
|
+
if (typeof tableName === "string" && !joinsNotNullableMap[tableName]) {
|
|
1010
|
+
result[objectName] = null;
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
return result;
|
|
1015
|
+
}
|
|
1016
|
+
function orderSelectedFields(fields, pathPrefix) {
|
|
1017
|
+
return Object.entries(fields).reduce((result, [name2, field]) => {
|
|
1018
|
+
if (typeof name2 !== "string") {
|
|
1019
|
+
return result;
|
|
1020
|
+
}
|
|
1021
|
+
const newPath = pathPrefix ? [...pathPrefix, name2] : [name2];
|
|
1022
|
+
if (is(field, Column) || is(field, SQL) || is(field, SQL.Aliased) || is(field, Subquery)) {
|
|
1023
|
+
result.push({ path: newPath, field });
|
|
1024
|
+
} else if (is(field, Table)) {
|
|
1025
|
+
result.push(...orderSelectedFields(field[Table.Symbol.Columns], newPath));
|
|
1026
|
+
} else {
|
|
1027
|
+
result.push(...orderSelectedFields(field, newPath));
|
|
1028
|
+
}
|
|
1029
|
+
return result;
|
|
1030
|
+
}, []);
|
|
1031
|
+
}
|
|
1032
|
+
function haveSameKeys(left, right) {
|
|
1033
|
+
const leftKeys = Object.keys(left);
|
|
1034
|
+
const rightKeys = Object.keys(right);
|
|
1035
|
+
if (leftKeys.length !== rightKeys.length) {
|
|
1036
|
+
return false;
|
|
1037
|
+
}
|
|
1038
|
+
for (const [index, key] of leftKeys.entries()) {
|
|
1039
|
+
if (key !== rightKeys[index]) {
|
|
1040
|
+
return false;
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
return true;
|
|
1044
|
+
}
|
|
1045
|
+
function mapUpdateSet(table, values) {
|
|
1046
|
+
const entries = Object.entries(values).filter(([, value]) => value !== undefined).map(([key, value]) => {
|
|
1047
|
+
if (is(value, SQL) || is(value, Column)) {
|
|
1048
|
+
return [key, value];
|
|
1049
|
+
} else {
|
|
1050
|
+
return [key, new Param(value, table[Table.Symbol.Columns][key])];
|
|
1051
|
+
}
|
|
1052
|
+
});
|
|
1053
|
+
if (entries.length === 0) {
|
|
1054
|
+
throw new Error("No values to set");
|
|
1055
|
+
}
|
|
1056
|
+
return Object.fromEntries(entries);
|
|
1057
|
+
}
|
|
1058
|
+
function applyMixins(baseClass, extendedClasses) {
|
|
1059
|
+
for (const extendedClass of extendedClasses) {
|
|
1060
|
+
for (const name2 of Object.getOwnPropertyNames(extendedClass.prototype)) {
|
|
1061
|
+
if (name2 === "constructor")
|
|
1062
|
+
continue;
|
|
1063
|
+
Object.defineProperty(baseClass.prototype, name2, Object.getOwnPropertyDescriptor(extendedClass.prototype, name2) || /* @__PURE__ */ Object.create(null));
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
function getTableColumns(table) {
|
|
1068
|
+
return table[Table.Symbol.Columns];
|
|
1069
|
+
}
|
|
1070
|
+
function getViewSelectedFields(view) {
|
|
1071
|
+
return view[ViewBaseConfig].selectedFields;
|
|
1072
|
+
}
|
|
1073
|
+
function getTableLikeName(table) {
|
|
1074
|
+
return is(table, Subquery) ? table._.alias : is(table, View) ? table[ViewBaseConfig].name : is(table, SQL) ? undefined : table[Table.Symbol.IsAlias] ? table[Table.Symbol.Name] : table[Table.Symbol.BaseName];
|
|
1075
|
+
}
|
|
1076
|
+
function getColumnNameAndConfig(a, b) {
|
|
1077
|
+
return {
|
|
1078
|
+
name: typeof a === "string" && a.length > 0 ? a : "",
|
|
1079
|
+
config: typeof a === "object" ? a : b
|
|
1080
|
+
};
|
|
1081
|
+
}
|
|
1082
|
+
function isConfig(data) {
|
|
1083
|
+
if (typeof data !== "object" || data === null)
|
|
1084
|
+
return false;
|
|
1085
|
+
if (data.constructor.name !== "Object")
|
|
1086
|
+
return false;
|
|
1087
|
+
if ("logger" in data) {
|
|
1088
|
+
const type = typeof data["logger"];
|
|
1089
|
+
if (type !== "boolean" && (type !== "object" || typeof data["logger"]["logQuery"] !== "function") && type !== "undefined")
|
|
1090
|
+
return false;
|
|
1091
|
+
return true;
|
|
1092
|
+
}
|
|
1093
|
+
if ("schema" in data) {
|
|
1094
|
+
const type = typeof data["schema"];
|
|
1095
|
+
if (type !== "object" && type !== "undefined")
|
|
1096
|
+
return false;
|
|
1097
|
+
return true;
|
|
1098
|
+
}
|
|
1099
|
+
if ("casing" in data) {
|
|
1100
|
+
const type = typeof data["casing"];
|
|
1101
|
+
if (type !== "string" && type !== "undefined")
|
|
1102
|
+
return false;
|
|
1103
|
+
return true;
|
|
1104
|
+
}
|
|
1105
|
+
if ("mode" in data) {
|
|
1106
|
+
if (data["mode"] !== "default" || data["mode"] !== "planetscale" || data["mode"] !== undefined)
|
|
1107
|
+
return false;
|
|
1108
|
+
return true;
|
|
1109
|
+
}
|
|
1110
|
+
if ("connection" in data) {
|
|
1111
|
+
const type = typeof data["connection"];
|
|
1112
|
+
if (type !== "string" && type !== "object" && type !== "undefined")
|
|
1113
|
+
return false;
|
|
1114
|
+
return true;
|
|
1115
|
+
}
|
|
1116
|
+
if ("client" in data) {
|
|
1117
|
+
const type = typeof data["client"];
|
|
1118
|
+
if (type !== "object" && type !== "function" && type !== "undefined")
|
|
1119
|
+
return false;
|
|
1120
|
+
return true;
|
|
1121
|
+
}
|
|
1122
|
+
if (Object.keys(data).length === 0)
|
|
1123
|
+
return true;
|
|
1124
|
+
return false;
|
|
1125
|
+
}
|
|
1126
|
+
var textDecoder;
|
|
1127
|
+
var init_utils = __esm(() => {
|
|
1128
|
+
init_column();
|
|
1129
|
+
init_entity();
|
|
1130
|
+
init_sql();
|
|
1131
|
+
init_subquery();
|
|
1132
|
+
init_table();
|
|
1133
|
+
init_view_common();
|
|
1134
|
+
textDecoder = typeof TextDecoder === "undefined" ? null : new TextDecoder;
|
|
1135
|
+
});
|
|
1136
|
+
|
|
1137
|
+
// ../../../../node_modules/drizzle-orm/pg-core/table.js
|
|
1138
|
+
var InlineForeignKeys, EnableRLS, PgTable;
|
|
1139
|
+
var init_table2 = __esm(() => {
|
|
1140
|
+
init_entity();
|
|
1141
|
+
init_table();
|
|
1142
|
+
InlineForeignKeys = Symbol.for("drizzle:PgInlineForeignKeys");
|
|
1143
|
+
EnableRLS = Symbol.for("drizzle:EnableRLS");
|
|
1144
|
+
PgTable = class PgTable extends Table {
|
|
1145
|
+
static [entityKind] = "PgTable";
|
|
1146
|
+
static Symbol = Object.assign({}, Table.Symbol, {
|
|
1147
|
+
InlineForeignKeys,
|
|
1148
|
+
EnableRLS
|
|
1149
|
+
});
|
|
1150
|
+
[InlineForeignKeys] = [];
|
|
1151
|
+
[EnableRLS] = false;
|
|
1152
|
+
[Table.Symbol.ExtraConfigBuilder] = undefined;
|
|
1153
|
+
[Table.Symbol.ExtraConfigColumns] = {};
|
|
1154
|
+
};
|
|
1155
|
+
});
|
|
1156
|
+
|
|
1157
|
+
// ../../../../node_modules/drizzle-orm/pg-core/primary-keys.js
|
|
1158
|
+
var PrimaryKeyBuilder, PrimaryKey;
|
|
1159
|
+
var init_primary_keys = __esm(() => {
|
|
1160
|
+
init_entity();
|
|
1161
|
+
init_table2();
|
|
1162
|
+
PrimaryKeyBuilder = class PrimaryKeyBuilder {
|
|
1163
|
+
static [entityKind] = "PgPrimaryKeyBuilder";
|
|
1164
|
+
columns;
|
|
1165
|
+
name;
|
|
1166
|
+
constructor(columns, name2) {
|
|
1167
|
+
this.columns = columns;
|
|
1168
|
+
this.name = name2;
|
|
1169
|
+
}
|
|
1170
|
+
build(table) {
|
|
1171
|
+
return new PrimaryKey(table, this.columns, this.name);
|
|
1172
|
+
}
|
|
1173
|
+
};
|
|
1174
|
+
PrimaryKey = class PrimaryKey {
|
|
1175
|
+
constructor(table, columns, name2) {
|
|
1176
|
+
this.table = table;
|
|
1177
|
+
this.columns = columns;
|
|
1178
|
+
this.name = name2;
|
|
1179
|
+
}
|
|
1180
|
+
static [entityKind] = "PgPrimaryKey";
|
|
1181
|
+
columns;
|
|
1182
|
+
name;
|
|
1183
|
+
getName() {
|
|
1184
|
+
return this.name ?? `${this.table[PgTable.Symbol.Name]}_${this.columns.map((column) => column.name).join("_")}_pk`;
|
|
1185
|
+
}
|
|
1186
|
+
};
|
|
1187
|
+
});
|
|
1188
|
+
|
|
1189
|
+
// ../../../../node_modules/drizzle-orm/sql/expressions/conditions.js
|
|
1190
|
+
function bindIfParam(value, column) {
|
|
1191
|
+
if (isDriverValueEncoder(column) && !isSQLWrapper(value) && !is(value, Param) && !is(value, Placeholder) && !is(value, Column) && !is(value, Table) && !is(value, View)) {
|
|
1192
|
+
return new Param(value, column);
|
|
1193
|
+
}
|
|
1194
|
+
return value;
|
|
1195
|
+
}
|
|
1196
|
+
function and(...unfilteredConditions) {
|
|
1197
|
+
const conditions = unfilteredConditions.filter((c) => c !== undefined);
|
|
1198
|
+
if (conditions.length === 0) {
|
|
1199
|
+
return;
|
|
1200
|
+
}
|
|
1201
|
+
if (conditions.length === 1) {
|
|
1202
|
+
return new SQL(conditions);
|
|
1203
|
+
}
|
|
1204
|
+
return new SQL([
|
|
1205
|
+
new StringChunk("("),
|
|
1206
|
+
sql.join(conditions, new StringChunk(" and ")),
|
|
1207
|
+
new StringChunk(")")
|
|
1208
|
+
]);
|
|
1209
|
+
}
|
|
1210
|
+
function or(...unfilteredConditions) {
|
|
1211
|
+
const conditions = unfilteredConditions.filter((c) => c !== undefined);
|
|
1212
|
+
if (conditions.length === 0) {
|
|
1213
|
+
return;
|
|
1214
|
+
}
|
|
1215
|
+
if (conditions.length === 1) {
|
|
1216
|
+
return new SQL(conditions);
|
|
1217
|
+
}
|
|
1218
|
+
return new SQL([
|
|
1219
|
+
new StringChunk("("),
|
|
1220
|
+
sql.join(conditions, new StringChunk(" or ")),
|
|
1221
|
+
new StringChunk(")")
|
|
1222
|
+
]);
|
|
1223
|
+
}
|
|
1224
|
+
function not(condition) {
|
|
1225
|
+
return sql`not ${condition}`;
|
|
1226
|
+
}
|
|
1227
|
+
function inArray(column, values) {
|
|
1228
|
+
if (Array.isArray(values)) {
|
|
1229
|
+
if (values.length === 0) {
|
|
1230
|
+
return sql`false`;
|
|
1231
|
+
}
|
|
1232
|
+
return sql`${column} in ${values.map((v) => bindIfParam(v, column))}`;
|
|
1233
|
+
}
|
|
1234
|
+
return sql`${column} in ${bindIfParam(values, column)}`;
|
|
1235
|
+
}
|
|
1236
|
+
function notInArray(column, values) {
|
|
1237
|
+
if (Array.isArray(values)) {
|
|
1238
|
+
if (values.length === 0) {
|
|
1239
|
+
return sql`true`;
|
|
1240
|
+
}
|
|
1241
|
+
return sql`${column} not in ${values.map((v) => bindIfParam(v, column))}`;
|
|
1242
|
+
}
|
|
1243
|
+
return sql`${column} not in ${bindIfParam(values, column)}`;
|
|
1244
|
+
}
|
|
1245
|
+
function isNull(value) {
|
|
1246
|
+
return sql`${value} is null`;
|
|
1247
|
+
}
|
|
1248
|
+
function isNotNull(value) {
|
|
1249
|
+
return sql`${value} is not null`;
|
|
1250
|
+
}
|
|
1251
|
+
function exists(subquery) {
|
|
1252
|
+
return sql`exists ${subquery}`;
|
|
1253
|
+
}
|
|
1254
|
+
function notExists(subquery) {
|
|
1255
|
+
return sql`not exists ${subquery}`;
|
|
1256
|
+
}
|
|
1257
|
+
function between(column, min, max) {
|
|
1258
|
+
return sql`${column} between ${bindIfParam(min, column)} and ${bindIfParam(max, column)}`;
|
|
1259
|
+
}
|
|
1260
|
+
function notBetween(column, min, max) {
|
|
1261
|
+
return sql`${column} not between ${bindIfParam(min, column)} and ${bindIfParam(max, column)}`;
|
|
1262
|
+
}
|
|
1263
|
+
function like(column, value) {
|
|
1264
|
+
return sql`${column} like ${value}`;
|
|
1265
|
+
}
|
|
1266
|
+
function notLike(column, value) {
|
|
1267
|
+
return sql`${column} not like ${value}`;
|
|
1268
|
+
}
|
|
1269
|
+
function ilike(column, value) {
|
|
1270
|
+
return sql`${column} ilike ${value}`;
|
|
1271
|
+
}
|
|
1272
|
+
function notIlike(column, value) {
|
|
1273
|
+
return sql`${column} not ilike ${value}`;
|
|
1274
|
+
}
|
|
1275
|
+
function arrayContains(column, values) {
|
|
1276
|
+
if (Array.isArray(values)) {
|
|
1277
|
+
if (values.length === 0) {
|
|
1278
|
+
throw new Error("arrayContains requires at least one value");
|
|
1279
|
+
}
|
|
1280
|
+
const array = sql`${bindIfParam(values, column)}`;
|
|
1281
|
+
return sql`${column} @> ${array}`;
|
|
1282
|
+
}
|
|
1283
|
+
return sql`${column} @> ${bindIfParam(values, column)}`;
|
|
1284
|
+
}
|
|
1285
|
+
function arrayContained(column, values) {
|
|
1286
|
+
if (Array.isArray(values)) {
|
|
1287
|
+
if (values.length === 0) {
|
|
1288
|
+
throw new Error("arrayContained requires at least one value");
|
|
1289
|
+
}
|
|
1290
|
+
const array = sql`${bindIfParam(values, column)}`;
|
|
1291
|
+
return sql`${column} <@ ${array}`;
|
|
1292
|
+
}
|
|
1293
|
+
return sql`${column} <@ ${bindIfParam(values, column)}`;
|
|
1294
|
+
}
|
|
1295
|
+
function arrayOverlaps(column, values) {
|
|
1296
|
+
if (Array.isArray(values)) {
|
|
1297
|
+
if (values.length === 0) {
|
|
1298
|
+
throw new Error("arrayOverlaps requires at least one value");
|
|
1299
|
+
}
|
|
1300
|
+
const array = sql`${bindIfParam(values, column)}`;
|
|
1301
|
+
return sql`${column} && ${array}`;
|
|
1302
|
+
}
|
|
1303
|
+
return sql`${column} && ${bindIfParam(values, column)}`;
|
|
1304
|
+
}
|
|
1305
|
+
var eq = (left, right) => {
|
|
1306
|
+
return sql`${left} = ${bindIfParam(right, left)}`;
|
|
1307
|
+
}, ne = (left, right) => {
|
|
1308
|
+
return sql`${left} <> ${bindIfParam(right, left)}`;
|
|
1309
|
+
}, gt = (left, right) => {
|
|
1310
|
+
return sql`${left} > ${bindIfParam(right, left)}`;
|
|
1311
|
+
}, gte = (left, right) => {
|
|
1312
|
+
return sql`${left} >= ${bindIfParam(right, left)}`;
|
|
1313
|
+
}, lt = (left, right) => {
|
|
1314
|
+
return sql`${left} < ${bindIfParam(right, left)}`;
|
|
1315
|
+
}, lte = (left, right) => {
|
|
1316
|
+
return sql`${left} <= ${bindIfParam(right, left)}`;
|
|
1317
|
+
};
|
|
1318
|
+
var init_conditions = __esm(() => {
|
|
1319
|
+
init_column();
|
|
1320
|
+
init_entity();
|
|
1321
|
+
init_table();
|
|
1322
|
+
init_sql();
|
|
1323
|
+
});
|
|
1324
|
+
|
|
1325
|
+
// ../../../../node_modules/drizzle-orm/sql/expressions/select.js
|
|
1326
|
+
function asc(column) {
|
|
1327
|
+
return sql`${column} asc`;
|
|
1328
|
+
}
|
|
1329
|
+
function desc(column) {
|
|
1330
|
+
return sql`${column} desc`;
|
|
1331
|
+
}
|
|
1332
|
+
var init_select = __esm(() => {
|
|
1333
|
+
init_sql();
|
|
1334
|
+
});
|
|
1335
|
+
|
|
1336
|
+
// ../../../../node_modules/drizzle-orm/sql/expressions/index.js
|
|
1337
|
+
var init_expressions = __esm(() => {
|
|
1338
|
+
init_conditions();
|
|
1339
|
+
init_select();
|
|
1340
|
+
});
|
|
1341
|
+
|
|
1342
|
+
// ../../../../node_modules/drizzle-orm/relations.js
|
|
1343
|
+
function getOperators() {
|
|
1344
|
+
return {
|
|
1345
|
+
and,
|
|
1346
|
+
between,
|
|
1347
|
+
eq,
|
|
1348
|
+
exists,
|
|
1349
|
+
gt,
|
|
1350
|
+
gte,
|
|
1351
|
+
ilike,
|
|
1352
|
+
inArray,
|
|
1353
|
+
isNull,
|
|
1354
|
+
isNotNull,
|
|
1355
|
+
like,
|
|
1356
|
+
lt,
|
|
1357
|
+
lte,
|
|
1358
|
+
ne,
|
|
1359
|
+
not,
|
|
1360
|
+
notBetween,
|
|
1361
|
+
notExists,
|
|
1362
|
+
notLike,
|
|
1363
|
+
notIlike,
|
|
1364
|
+
notInArray,
|
|
1365
|
+
or,
|
|
1366
|
+
sql
|
|
1367
|
+
};
|
|
1368
|
+
}
|
|
1369
|
+
function getOrderByOperators() {
|
|
1370
|
+
return {
|
|
1371
|
+
sql,
|
|
1372
|
+
asc,
|
|
1373
|
+
desc
|
|
1374
|
+
};
|
|
1375
|
+
}
|
|
1376
|
+
function extractTablesRelationalConfig(schema, configHelpers) {
|
|
1377
|
+
if (Object.keys(schema).length === 1 && "default" in schema && !is(schema["default"], Table)) {
|
|
1378
|
+
schema = schema["default"];
|
|
1379
|
+
}
|
|
1380
|
+
const tableNamesMap = {};
|
|
1381
|
+
const relationsBuffer = {};
|
|
1382
|
+
const tablesConfig = {};
|
|
1383
|
+
for (const [key, value] of Object.entries(schema)) {
|
|
1384
|
+
if (is(value, Table)) {
|
|
1385
|
+
const dbName = getTableUniqueName(value);
|
|
1386
|
+
const bufferedRelations = relationsBuffer[dbName];
|
|
1387
|
+
tableNamesMap[dbName] = key;
|
|
1388
|
+
tablesConfig[key] = {
|
|
1389
|
+
tsName: key,
|
|
1390
|
+
dbName: value[Table.Symbol.Name],
|
|
1391
|
+
schema: value[Table.Symbol.Schema],
|
|
1392
|
+
columns: value[Table.Symbol.Columns],
|
|
1393
|
+
relations: bufferedRelations?.relations ?? {},
|
|
1394
|
+
primaryKey: bufferedRelations?.primaryKey ?? []
|
|
1395
|
+
};
|
|
1396
|
+
for (const column of Object.values(value[Table.Symbol.Columns])) {
|
|
1397
|
+
if (column.primary) {
|
|
1398
|
+
tablesConfig[key].primaryKey.push(column);
|
|
1399
|
+
}
|
|
1400
|
+
}
|
|
1401
|
+
const extraConfig = value[Table.Symbol.ExtraConfigBuilder]?.(value[Table.Symbol.ExtraConfigColumns]);
|
|
1402
|
+
if (extraConfig) {
|
|
1403
|
+
for (const configEntry of Object.values(extraConfig)) {
|
|
1404
|
+
if (is(configEntry, PrimaryKeyBuilder)) {
|
|
1405
|
+
tablesConfig[key].primaryKey.push(...configEntry.columns);
|
|
1406
|
+
}
|
|
1407
|
+
}
|
|
1408
|
+
}
|
|
1409
|
+
} else if (is(value, Relations)) {
|
|
1410
|
+
const dbName = getTableUniqueName(value.table);
|
|
1411
|
+
const tableName = tableNamesMap[dbName];
|
|
1412
|
+
const relations2 = value.config(configHelpers(value.table));
|
|
1413
|
+
let primaryKey;
|
|
1414
|
+
for (const [relationName, relation] of Object.entries(relations2)) {
|
|
1415
|
+
if (tableName) {
|
|
1416
|
+
const tableConfig = tablesConfig[tableName];
|
|
1417
|
+
tableConfig.relations[relationName] = relation;
|
|
1418
|
+
if (primaryKey) {
|
|
1419
|
+
tableConfig.primaryKey.push(...primaryKey);
|
|
1420
|
+
}
|
|
1421
|
+
} else {
|
|
1422
|
+
if (!(dbName in relationsBuffer)) {
|
|
1423
|
+
relationsBuffer[dbName] = {
|
|
1424
|
+
relations: {},
|
|
1425
|
+
primaryKey
|
|
1426
|
+
};
|
|
1427
|
+
}
|
|
1428
|
+
relationsBuffer[dbName].relations[relationName] = relation;
|
|
1429
|
+
}
|
|
1430
|
+
}
|
|
1431
|
+
}
|
|
1432
|
+
}
|
|
1433
|
+
return { tables: tablesConfig, tableNamesMap };
|
|
1434
|
+
}
|
|
1435
|
+
function relations(table, relations2) {
|
|
1436
|
+
return new Relations(table, (helpers) => Object.fromEntries(Object.entries(relations2(helpers)).map(([key, value]) => [
|
|
1437
|
+
key,
|
|
1438
|
+
value.withFieldName(key)
|
|
1439
|
+
])));
|
|
1440
|
+
}
|
|
1441
|
+
function createOne(sourceTable) {
|
|
1442
|
+
return function one(table, config) {
|
|
1443
|
+
return new One(sourceTable, table, config, config?.fields.reduce((res, f) => res && f.notNull, true) ?? false);
|
|
1444
|
+
};
|
|
1445
|
+
}
|
|
1446
|
+
function createMany(sourceTable) {
|
|
1447
|
+
return function many(referencedTable, config) {
|
|
1448
|
+
return new Many(sourceTable, referencedTable, config);
|
|
1449
|
+
};
|
|
1450
|
+
}
|
|
1451
|
+
function normalizeRelation(schema, tableNamesMap, relation) {
|
|
1452
|
+
if (is(relation, One) && relation.config) {
|
|
1453
|
+
return {
|
|
1454
|
+
fields: relation.config.fields,
|
|
1455
|
+
references: relation.config.references
|
|
1456
|
+
};
|
|
1457
|
+
}
|
|
1458
|
+
const referencedTableTsName = tableNamesMap[getTableUniqueName(relation.referencedTable)];
|
|
1459
|
+
if (!referencedTableTsName) {
|
|
1460
|
+
throw new Error(`Table "${relation.referencedTable[Table.Symbol.Name]}" not found in schema`);
|
|
1461
|
+
}
|
|
1462
|
+
const referencedTableConfig = schema[referencedTableTsName];
|
|
1463
|
+
if (!referencedTableConfig) {
|
|
1464
|
+
throw new Error(`Table "${referencedTableTsName}" not found in schema`);
|
|
1465
|
+
}
|
|
1466
|
+
const sourceTable = relation.sourceTable;
|
|
1467
|
+
const sourceTableTsName = tableNamesMap[getTableUniqueName(sourceTable)];
|
|
1468
|
+
if (!sourceTableTsName) {
|
|
1469
|
+
throw new Error(`Table "${sourceTable[Table.Symbol.Name]}" not found in schema`);
|
|
1470
|
+
}
|
|
1471
|
+
const reverseRelations = [];
|
|
1472
|
+
for (const referencedTableRelation of Object.values(referencedTableConfig.relations)) {
|
|
1473
|
+
if (relation.relationName && relation !== referencedTableRelation && referencedTableRelation.relationName === relation.relationName || !relation.relationName && referencedTableRelation.referencedTable === relation.sourceTable) {
|
|
1474
|
+
reverseRelations.push(referencedTableRelation);
|
|
1475
|
+
}
|
|
1476
|
+
}
|
|
1477
|
+
if (reverseRelations.length > 1) {
|
|
1478
|
+
throw relation.relationName ? new Error(`There are multiple relations with name "${relation.relationName}" in table "${referencedTableTsName}"`) : new Error(`There are multiple relations between "${referencedTableTsName}" and "${relation.sourceTable[Table.Symbol.Name]}". Please specify relation name`);
|
|
1479
|
+
}
|
|
1480
|
+
if (reverseRelations[0] && is(reverseRelations[0], One) && reverseRelations[0].config) {
|
|
1481
|
+
return {
|
|
1482
|
+
fields: reverseRelations[0].config.references,
|
|
1483
|
+
references: reverseRelations[0].config.fields
|
|
1484
|
+
};
|
|
1485
|
+
}
|
|
1486
|
+
throw new Error(`There is not enough information to infer relation "${sourceTableTsName}.${relation.fieldName}"`);
|
|
1487
|
+
}
|
|
1488
|
+
function createTableRelationsHelpers(sourceTable) {
|
|
1489
|
+
return {
|
|
1490
|
+
one: createOne(sourceTable),
|
|
1491
|
+
many: createMany(sourceTable)
|
|
1492
|
+
};
|
|
1493
|
+
}
|
|
1494
|
+
function mapRelationalRow(tablesConfig, tableConfig, row, buildQueryResultSelection, mapColumnValue = (value) => value) {
|
|
1495
|
+
const result = {};
|
|
1496
|
+
for (const [
|
|
1497
|
+
selectionItemIndex,
|
|
1498
|
+
selectionItem
|
|
1499
|
+
] of buildQueryResultSelection.entries()) {
|
|
1500
|
+
if (selectionItem.isJson) {
|
|
1501
|
+
const relation = tableConfig.relations[selectionItem.tsKey];
|
|
1502
|
+
const rawSubRows = row[selectionItemIndex];
|
|
1503
|
+
const subRows = typeof rawSubRows === "string" ? JSON.parse(rawSubRows) : rawSubRows;
|
|
1504
|
+
result[selectionItem.tsKey] = is(relation, One) ? subRows && mapRelationalRow(tablesConfig, tablesConfig[selectionItem.relationTableTsKey], subRows, selectionItem.selection, mapColumnValue) : subRows.map((subRow) => mapRelationalRow(tablesConfig, tablesConfig[selectionItem.relationTableTsKey], subRow, selectionItem.selection, mapColumnValue));
|
|
1505
|
+
} else {
|
|
1506
|
+
const value = mapColumnValue(row[selectionItemIndex]);
|
|
1507
|
+
const field = selectionItem.field;
|
|
1508
|
+
let decoder;
|
|
1509
|
+
if (is(field, Column)) {
|
|
1510
|
+
decoder = field;
|
|
1511
|
+
} else if (is(field, SQL)) {
|
|
1512
|
+
decoder = field.decoder;
|
|
1513
|
+
} else {
|
|
1514
|
+
decoder = field.sql.decoder;
|
|
1515
|
+
}
|
|
1516
|
+
result[selectionItem.tsKey] = value === null ? null : decoder.mapFromDriverValue(value);
|
|
1517
|
+
}
|
|
1518
|
+
}
|
|
1519
|
+
return result;
|
|
1520
|
+
}
|
|
1521
|
+
var Relation, Relations, One, Many;
|
|
1522
|
+
var init_relations = __esm(() => {
|
|
1523
|
+
init_table();
|
|
1524
|
+
init_column();
|
|
1525
|
+
init_entity();
|
|
1526
|
+
init_primary_keys();
|
|
1527
|
+
init_expressions();
|
|
1528
|
+
init_sql();
|
|
1529
|
+
Relation = class Relation {
|
|
1530
|
+
constructor(sourceTable, referencedTable, relationName) {
|
|
1531
|
+
this.sourceTable = sourceTable;
|
|
1532
|
+
this.referencedTable = referencedTable;
|
|
1533
|
+
this.relationName = relationName;
|
|
1534
|
+
this.referencedTableName = referencedTable[Table.Symbol.Name];
|
|
1535
|
+
}
|
|
1536
|
+
static [entityKind] = "Relation";
|
|
1537
|
+
referencedTableName;
|
|
1538
|
+
fieldName;
|
|
1539
|
+
};
|
|
1540
|
+
Relations = class Relations {
|
|
1541
|
+
constructor(table, config) {
|
|
1542
|
+
this.table = table;
|
|
1543
|
+
this.config = config;
|
|
1544
|
+
}
|
|
1545
|
+
static [entityKind] = "Relations";
|
|
1546
|
+
};
|
|
1547
|
+
One = class One extends Relation {
|
|
1548
|
+
constructor(sourceTable, referencedTable, config, isNullable) {
|
|
1549
|
+
super(sourceTable, referencedTable, config?.relationName);
|
|
1550
|
+
this.config = config;
|
|
1551
|
+
this.isNullable = isNullable;
|
|
1552
|
+
}
|
|
1553
|
+
static [entityKind] = "One";
|
|
1554
|
+
withFieldName(fieldName) {
|
|
1555
|
+
const relation = new One(this.sourceTable, this.referencedTable, this.config, this.isNullable);
|
|
1556
|
+
relation.fieldName = fieldName;
|
|
1557
|
+
return relation;
|
|
1558
|
+
}
|
|
1559
|
+
};
|
|
1560
|
+
Many = class Many extends Relation {
|
|
1561
|
+
constructor(sourceTable, referencedTable, config) {
|
|
1562
|
+
super(sourceTable, referencedTable, config?.relationName);
|
|
1563
|
+
this.config = config;
|
|
1564
|
+
}
|
|
1565
|
+
static [entityKind] = "Many";
|
|
1566
|
+
withFieldName(fieldName) {
|
|
1567
|
+
const relation = new Many(this.sourceTable, this.referencedTable, this.config);
|
|
1568
|
+
relation.fieldName = fieldName;
|
|
1569
|
+
return relation;
|
|
1570
|
+
}
|
|
1571
|
+
};
|
|
1572
|
+
});
|
|
1573
|
+
|
|
1574
|
+
// ../../../../node_modules/drizzle-orm/sql/functions/aggregate.js
|
|
1575
|
+
function count(expression) {
|
|
1576
|
+
return sql`count(${expression || sql.raw("*")})`.mapWith(Number);
|
|
1577
|
+
}
|
|
1578
|
+
function countDistinct(expression) {
|
|
1579
|
+
return sql`count(distinct ${expression})`.mapWith(Number);
|
|
1580
|
+
}
|
|
1581
|
+
function avg(expression) {
|
|
1582
|
+
return sql`avg(${expression})`.mapWith(String);
|
|
1583
|
+
}
|
|
1584
|
+
function avgDistinct(expression) {
|
|
1585
|
+
return sql`avg(distinct ${expression})`.mapWith(String);
|
|
1586
|
+
}
|
|
1587
|
+
function sum(expression) {
|
|
1588
|
+
return sql`sum(${expression})`.mapWith(String);
|
|
1589
|
+
}
|
|
1590
|
+
function sumDistinct(expression) {
|
|
1591
|
+
return sql`sum(distinct ${expression})`.mapWith(String);
|
|
1592
|
+
}
|
|
1593
|
+
function max(expression) {
|
|
1594
|
+
return sql`max(${expression})`.mapWith(is(expression, Column) ? expression : String);
|
|
1595
|
+
}
|
|
1596
|
+
function min(expression) {
|
|
1597
|
+
return sql`min(${expression})`.mapWith(is(expression, Column) ? expression : String);
|
|
1598
|
+
}
|
|
1599
|
+
var init_aggregate = __esm(() => {
|
|
1600
|
+
init_column();
|
|
1601
|
+
init_entity();
|
|
1602
|
+
init_sql();
|
|
1603
|
+
});
|
|
1604
|
+
|
|
1605
|
+
// ../../../../node_modules/drizzle-orm/sql/functions/vector.js
|
|
1606
|
+
function toSql(value) {
|
|
1607
|
+
return JSON.stringify(value);
|
|
1608
|
+
}
|
|
1609
|
+
function l2Distance(column, value) {
|
|
1610
|
+
if (Array.isArray(value)) {
|
|
1611
|
+
return sql`${column} <-> ${toSql(value)}`;
|
|
1612
|
+
}
|
|
1613
|
+
return sql`${column} <-> ${value}`;
|
|
1614
|
+
}
|
|
1615
|
+
function l1Distance(column, value) {
|
|
1616
|
+
if (Array.isArray(value)) {
|
|
1617
|
+
return sql`${column} <+> ${toSql(value)}`;
|
|
1618
|
+
}
|
|
1619
|
+
return sql`${column} <+> ${value}`;
|
|
1620
|
+
}
|
|
1621
|
+
function innerProduct(column, value) {
|
|
1622
|
+
if (Array.isArray(value)) {
|
|
1623
|
+
return sql`${column} <#> ${toSql(value)}`;
|
|
1624
|
+
}
|
|
1625
|
+
return sql`${column} <#> ${value}`;
|
|
1626
|
+
}
|
|
1627
|
+
function cosineDistance(column, value) {
|
|
1628
|
+
if (Array.isArray(value)) {
|
|
1629
|
+
return sql`${column} <=> ${toSql(value)}`;
|
|
1630
|
+
}
|
|
1631
|
+
return sql`${column} <=> ${value}`;
|
|
1632
|
+
}
|
|
1633
|
+
function hammingDistance(column, value) {
|
|
1634
|
+
if (Array.isArray(value)) {
|
|
1635
|
+
return sql`${column} <~> ${toSql(value)}`;
|
|
1636
|
+
}
|
|
1637
|
+
return sql`${column} <~> ${value}`;
|
|
1638
|
+
}
|
|
1639
|
+
function jaccardDistance(column, value) {
|
|
1640
|
+
if (Array.isArray(value)) {
|
|
1641
|
+
return sql`${column} <%> ${toSql(value)}`;
|
|
1642
|
+
}
|
|
1643
|
+
return sql`${column} <%> ${value}`;
|
|
1644
|
+
}
|
|
1645
|
+
var init_vector = __esm(() => {
|
|
1646
|
+
init_sql();
|
|
1647
|
+
});
|
|
1648
|
+
|
|
1649
|
+
// ../../../../node_modules/drizzle-orm/sql/functions/index.js
|
|
1650
|
+
var init_functions = __esm(() => {
|
|
1651
|
+
init_aggregate();
|
|
1652
|
+
init_vector();
|
|
1653
|
+
});
|
|
1654
|
+
|
|
1655
|
+
// ../../../../node_modules/drizzle-orm/sql/index.js
|
|
1656
|
+
var init_sql2 = __esm(() => {
|
|
1657
|
+
init_expressions();
|
|
1658
|
+
init_functions();
|
|
1659
|
+
init_sql();
|
|
1660
|
+
});
|
|
1661
|
+
|
|
1662
|
+
// ../../../../node_modules/drizzle-orm/index.js
|
|
1663
|
+
var exports_drizzle_orm = {};
|
|
1664
|
+
__export(exports_drizzle_orm, {
|
|
1665
|
+
textDecoder: () => textDecoder,
|
|
1666
|
+
sumDistinct: () => sumDistinct,
|
|
1667
|
+
sum: () => sum,
|
|
1668
|
+
sql: () => sql,
|
|
1669
|
+
relations: () => relations,
|
|
1670
|
+
placeholder: () => placeholder,
|
|
1671
|
+
param: () => param,
|
|
1672
|
+
orderSelectedFields: () => orderSelectedFields,
|
|
1673
|
+
or: () => or,
|
|
1674
|
+
notLike: () => notLike,
|
|
1675
|
+
notInArray: () => notInArray,
|
|
1676
|
+
notIlike: () => notIlike,
|
|
1677
|
+
notExists: () => notExists,
|
|
1678
|
+
notBetween: () => notBetween,
|
|
1679
|
+
not: () => not,
|
|
1680
|
+
normalizeRelation: () => normalizeRelation,
|
|
1681
|
+
noopMapper: () => noopMapper,
|
|
1682
|
+
noopEncoder: () => noopEncoder,
|
|
1683
|
+
noopDecoder: () => noopDecoder,
|
|
1684
|
+
ne: () => ne,
|
|
1685
|
+
name: () => name,
|
|
1686
|
+
min: () => min,
|
|
1687
|
+
max: () => max,
|
|
1688
|
+
mapUpdateSet: () => mapUpdateSet,
|
|
1689
|
+
mapResultRow: () => mapResultRow,
|
|
1690
|
+
mapRelationalRow: () => mapRelationalRow,
|
|
1691
|
+
mapColumnsInSQLToAlias: () => mapColumnsInSQLToAlias,
|
|
1692
|
+
mapColumnsInAliasedSQLToAlias: () => mapColumnsInAliasedSQLToAlias,
|
|
1693
|
+
lte: () => lte,
|
|
1694
|
+
lt: () => lt,
|
|
1695
|
+
like: () => like,
|
|
1696
|
+
l2Distance: () => l2Distance,
|
|
1697
|
+
l1Distance: () => l1Distance,
|
|
1698
|
+
jaccardDistance: () => jaccardDistance,
|
|
1699
|
+
isView: () => isView,
|
|
1700
|
+
isTable: () => isTable,
|
|
1701
|
+
isSQLWrapper: () => isSQLWrapper,
|
|
1702
|
+
isNull: () => isNull,
|
|
1703
|
+
isNotNull: () => isNotNull,
|
|
1704
|
+
isDriverValueEncoder: () => isDriverValueEncoder,
|
|
1705
|
+
isConfig: () => isConfig,
|
|
1706
|
+
is: () => is,
|
|
1707
|
+
innerProduct: () => innerProduct,
|
|
1708
|
+
inArray: () => inArray,
|
|
1709
|
+
ilike: () => ilike,
|
|
1710
|
+
haveSameKeys: () => haveSameKeys,
|
|
1711
|
+
hasOwnEntityKind: () => hasOwnEntityKind,
|
|
1712
|
+
hammingDistance: () => hammingDistance,
|
|
1713
|
+
gte: () => gte,
|
|
1714
|
+
gt: () => gt,
|
|
1715
|
+
getViewSelectedFields: () => getViewSelectedFields,
|
|
1716
|
+
getViewName: () => getViewName,
|
|
1717
|
+
getTableUniqueName: () => getTableUniqueName,
|
|
1718
|
+
getTableName: () => getTableName,
|
|
1719
|
+
getTableLikeName: () => getTableLikeName,
|
|
1720
|
+
getTableColumns: () => getTableColumns,
|
|
1721
|
+
getOrderByOperators: () => getOrderByOperators,
|
|
1722
|
+
getOperators: () => getOperators,
|
|
1723
|
+
getColumnNameAndConfig: () => getColumnNameAndConfig,
|
|
1724
|
+
fillPlaceholders: () => fillPlaceholders,
|
|
1725
|
+
extractTablesRelationalConfig: () => extractTablesRelationalConfig,
|
|
1726
|
+
exists: () => exists,
|
|
1727
|
+
eq: () => eq,
|
|
1728
|
+
entityKind: () => entityKind,
|
|
1729
|
+
desc: () => desc,
|
|
1730
|
+
createTableRelationsHelpers: () => createTableRelationsHelpers,
|
|
1731
|
+
createOne: () => createOne,
|
|
1732
|
+
createMany: () => createMany,
|
|
1733
|
+
countDistinct: () => countDistinct,
|
|
1734
|
+
count: () => count,
|
|
1735
|
+
cosineDistance: () => cosineDistance,
|
|
1736
|
+
bindIfParam: () => bindIfParam,
|
|
1737
|
+
between: () => between,
|
|
1738
|
+
avgDistinct: () => avgDistinct,
|
|
1739
|
+
avg: () => avg,
|
|
1740
|
+
asc: () => asc,
|
|
1741
|
+
arrayOverlaps: () => arrayOverlaps,
|
|
1742
|
+
arrayContains: () => arrayContains,
|
|
1743
|
+
arrayContained: () => arrayContained,
|
|
1744
|
+
applyMixins: () => applyMixins,
|
|
1745
|
+
and: () => and,
|
|
1746
|
+
aliasedTableColumn: () => aliasedTableColumn,
|
|
1747
|
+
aliasedTable: () => aliasedTable,
|
|
1748
|
+
aliasedRelation: () => aliasedRelation,
|
|
1749
|
+
WithSubquery: () => WithSubquery,
|
|
1750
|
+
ViewBaseConfig: () => ViewBaseConfig,
|
|
1751
|
+
View: () => View,
|
|
1752
|
+
TransactionRollbackError: () => TransactionRollbackError,
|
|
1753
|
+
TableAliasProxyHandler: () => TableAliasProxyHandler,
|
|
1754
|
+
Table: () => Table,
|
|
1755
|
+
Subquery: () => Subquery,
|
|
1756
|
+
StringChunk: () => StringChunk,
|
|
1757
|
+
Schema: () => Schema,
|
|
1758
|
+
SQL: () => SQL,
|
|
1759
|
+
Relations: () => Relations,
|
|
1760
|
+
RelationTableAliasProxyHandler: () => RelationTableAliasProxyHandler,
|
|
1761
|
+
Relation: () => Relation,
|
|
1762
|
+
QueryPromise: () => QueryPromise,
|
|
1763
|
+
Placeholder: () => Placeholder,
|
|
1764
|
+
Param: () => Param,
|
|
1765
|
+
OriginalName: () => OriginalName,
|
|
1766
|
+
One: () => One,
|
|
1767
|
+
NoopLogger: () => NoopLogger,
|
|
1768
|
+
Name: () => Name,
|
|
1769
|
+
Many: () => Many,
|
|
1770
|
+
IsAlias: () => IsAlias,
|
|
1771
|
+
FakePrimitiveParam: () => FakePrimitiveParam,
|
|
1772
|
+
ExtraConfigColumns: () => ExtraConfigColumns,
|
|
1773
|
+
ExtraConfigBuilder: () => ExtraConfigBuilder,
|
|
1774
|
+
DrizzleQueryError: () => DrizzleQueryError,
|
|
1775
|
+
DrizzleError: () => DrizzleError,
|
|
1776
|
+
DefaultLogger: () => DefaultLogger,
|
|
1777
|
+
ConsoleLogWriter: () => ConsoleLogWriter,
|
|
1778
|
+
Columns: () => Columns,
|
|
1779
|
+
ColumnBuilder: () => ColumnBuilder,
|
|
1780
|
+
ColumnAliasProxyHandler: () => ColumnAliasProxyHandler,
|
|
1781
|
+
Column: () => Column,
|
|
1782
|
+
BaseName: () => BaseName
|
|
1783
|
+
});
|
|
1784
|
+
var init_drizzle_orm = __esm(() => {
|
|
1785
|
+
init_alias();
|
|
1786
|
+
init_column_builder();
|
|
1787
|
+
init_column();
|
|
1788
|
+
init_entity();
|
|
1789
|
+
init_errors();
|
|
1790
|
+
init_logger();
|
|
1791
|
+
init_query_promise();
|
|
1792
|
+
init_relations();
|
|
1793
|
+
init_sql2();
|
|
1794
|
+
init_subquery();
|
|
1795
|
+
init_table();
|
|
1796
|
+
init_utils();
|
|
1797
|
+
init_view_common();
|
|
1798
|
+
});
|
|
3
1799
|
|
|
4
1800
|
// index.ts
|
|
5
1801
|
import {
|
|
@@ -8,8 +1804,25 @@ import {
|
|
|
8
1804
|
import crypto from "node:crypto";
|
|
9
1805
|
|
|
10
1806
|
// TrajectoryLoggerService.ts
|
|
11
|
-
import {
|
|
1807
|
+
import {
|
|
1808
|
+
logger as logger2,
|
|
1809
|
+
Service,
|
|
1810
|
+
getTrajectoryContext,
|
|
1811
|
+
runWithTrajectoryContext,
|
|
1812
|
+
setTrajectoryContextManager,
|
|
1813
|
+
ModelType
|
|
1814
|
+
} from "@elizaos/core";
|
|
12
1815
|
import { v4 as uuidv4 } from "uuid";
|
|
1816
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
1817
|
+
var trajectoryStorage = new AsyncLocalStorage;
|
|
1818
|
+
setTrajectoryContextManager({
|
|
1819
|
+
run(context, fn) {
|
|
1820
|
+
return trajectoryStorage.run(context, fn);
|
|
1821
|
+
},
|
|
1822
|
+
active() {
|
|
1823
|
+
return trajectoryStorage.getStore();
|
|
1824
|
+
}
|
|
1825
|
+
});
|
|
13
1826
|
function asNumber(value) {
|
|
14
1827
|
if (typeof value === "number" && Number.isFinite(value))
|
|
15
1828
|
return value;
|
|
@@ -67,6 +1880,96 @@ class TrajectoryLoggerService extends Service {
|
|
|
67
1880
|
capabilityDescription = "Captures and persists LLM calls, provider accesses, and full trajectories for debugging, analysis, and RL training";
|
|
68
1881
|
enabled = true;
|
|
69
1882
|
initialized = false;
|
|
1883
|
+
observationBuffer = [];
|
|
1884
|
+
observationFlushTimer = null;
|
|
1885
|
+
observationFlushInProgress = false;
|
|
1886
|
+
OBSERVATION_BUFFER_THRESHOLD = 5;
|
|
1887
|
+
OBSERVATION_FLUSH_INTERVAL_MS = 10 * 60 * 1000;
|
|
1888
|
+
pushChatExchange(exchange) {
|
|
1889
|
+
this.observationBuffer.push(exchange);
|
|
1890
|
+
if (this.observationBuffer.length >= this.OBSERVATION_BUFFER_THRESHOLD) {
|
|
1891
|
+
this.flushObservationBuffer().catch(() => {});
|
|
1892
|
+
return;
|
|
1893
|
+
}
|
|
1894
|
+
if (this.observationFlushTimer)
|
|
1895
|
+
clearTimeout(this.observationFlushTimer);
|
|
1896
|
+
this.observationFlushTimer = setTimeout(() => {
|
|
1897
|
+
this.flushObservationBuffer().catch(() => {});
|
|
1898
|
+
}, this.OBSERVATION_FLUSH_INTERVAL_MS);
|
|
1899
|
+
}
|
|
1900
|
+
async flushObservationBuffer() {
|
|
1901
|
+
if (this.observationFlushInProgress)
|
|
1902
|
+
return [];
|
|
1903
|
+
this.observationFlushInProgress = true;
|
|
1904
|
+
if (this.observationBuffer.length === 0) {
|
|
1905
|
+
this.observationFlushInProgress = false;
|
|
1906
|
+
return [];
|
|
1907
|
+
}
|
|
1908
|
+
const exchanges = this.observationBuffer.splice(0, this.observationBuffer.length);
|
|
1909
|
+
if (this.observationFlushTimer) {
|
|
1910
|
+
clearTimeout(this.observationFlushTimer);
|
|
1911
|
+
this.observationFlushTimer = null;
|
|
1912
|
+
}
|
|
1913
|
+
const OBSERVATION_EXTRACTION_PROMPT = `You are analyzing recent conversation exchanges between a user and an AI assistant.
|
|
1914
|
+
Extract any durable observations about the user that would be useful across future sessions.
|
|
1915
|
+
|
|
1916
|
+
Categories to look for:
|
|
1917
|
+
- Preferences (tools, languages, workflows, communication style)
|
|
1918
|
+
- Facts (role, location, projects they work on, tech stack)
|
|
1919
|
+
- Standing instructions (things they always/never want)
|
|
1920
|
+
- Patterns (recurring topics, how they like to work)
|
|
1921
|
+
|
|
1922
|
+
Return ONLY a JSON array of short observation strings (max 150 chars each).
|
|
1923
|
+
If nothing meaningful is found, return an empty array [].
|
|
1924
|
+
Do NOT include observations about the conversation itself, only about the user.
|
|
1925
|
+
|
|
1926
|
+
Recent exchanges:
|
|
1927
|
+
`;
|
|
1928
|
+
const exchangeText = exchanges.map((e, i) => `Exchange ${i + 1}:
|
|
1929
|
+
User: ${e.userPrompt.slice(0, 500)}
|
|
1930
|
+
Assistant: ${e.response.slice(0, 500)}`).join(`
|
|
1931
|
+
|
|
1932
|
+
`);
|
|
1933
|
+
const prompt = OBSERVATION_EXTRACTION_PROMPT + exchangeText;
|
|
1934
|
+
const runtimeAny = this.runtime;
|
|
1935
|
+
try {
|
|
1936
|
+
runtimeAny.__orchestratorTrajectoryCtx = {
|
|
1937
|
+
source: "orchestrator",
|
|
1938
|
+
decisionType: "observation-extraction"
|
|
1939
|
+
};
|
|
1940
|
+
const result = await this.runtime.useModel(ModelType.TEXT_SMALL, {
|
|
1941
|
+
prompt,
|
|
1942
|
+
maxTokens: 512,
|
|
1943
|
+
temperature: 0
|
|
1944
|
+
});
|
|
1945
|
+
const jsonMatch = result.match(/\[[\s\S]*\]/);
|
|
1946
|
+
if (!jsonMatch)
|
|
1947
|
+
return [];
|
|
1948
|
+
const parsed = JSON.parse(jsonMatch[0]);
|
|
1949
|
+
if (!Array.isArray(parsed))
|
|
1950
|
+
return [];
|
|
1951
|
+
const observations = parsed.filter((s) => typeof s === "string" && s.length > 0).map((s) => s.slice(0, 150));
|
|
1952
|
+
if (observations.length === 0)
|
|
1953
|
+
return [];
|
|
1954
|
+
const lastExchange = exchanges[exchanges.length - 1];
|
|
1955
|
+
await this.withTrajectoryWriteLock(lastExchange.trajectoryId, async () => {
|
|
1956
|
+
const trajectory = await this.getTrajectoryById(lastExchange.trajectoryId);
|
|
1957
|
+
if (trajectory) {
|
|
1958
|
+
const meta = trajectory.metadata ?? {};
|
|
1959
|
+
const existing = Array.isArray(meta.observations) ? meta.observations : [];
|
|
1960
|
+
meta.observations = [...existing, ...observations].slice(-30);
|
|
1961
|
+
trajectory.metadata = meta;
|
|
1962
|
+
await this.persistTrajectory(lastExchange.trajectoryId, trajectory, trajectory.metrics?.finalStatus || "completed");
|
|
1963
|
+
}
|
|
1964
|
+
});
|
|
1965
|
+
return observations;
|
|
1966
|
+
} catch {
|
|
1967
|
+
return [];
|
|
1968
|
+
} finally {
|
|
1969
|
+
delete runtimeAny.__orchestratorTrajectoryCtx;
|
|
1970
|
+
this.observationFlushInProgress = false;
|
|
1971
|
+
}
|
|
1972
|
+
}
|
|
70
1973
|
activeStepIds = new Map;
|
|
71
1974
|
stepToTrajectory = new Map;
|
|
72
1975
|
writeQueues = new Map;
|
|
@@ -85,7 +1988,7 @@ class TrajectoryLoggerService extends Service {
|
|
|
85
1988
|
return this.enabled;
|
|
86
1989
|
}
|
|
87
1990
|
async getSqlHelper() {
|
|
88
|
-
const drizzle = await
|
|
1991
|
+
const drizzle = await Promise.resolve().then(() => (init_drizzle_orm(), exports_drizzle_orm));
|
|
89
1992
|
return drizzle.sql;
|
|
90
1993
|
}
|
|
91
1994
|
async executeRawSql(sqlText) {
|
|
@@ -106,13 +2009,36 @@ class TrajectoryLoggerService extends Service {
|
|
|
106
2009
|
return;
|
|
107
2010
|
const runtime = this.runtime;
|
|
108
2011
|
if (!runtime?.adapter) {
|
|
109
|
-
|
|
2012
|
+
logger2.warn("[trajectory-logger] No runtime adapter available, skipping initialization");
|
|
110
2013
|
return;
|
|
111
2014
|
}
|
|
112
2015
|
await this.ensureTablesExist();
|
|
113
2016
|
await this.backfillTrajectoriesMissingLlmCalls();
|
|
2017
|
+
const originalUseModel = runtime.useModel;
|
|
2018
|
+
if (typeof originalUseModel === "function") {
|
|
2019
|
+
const patchedUseModel = async function(...args) {
|
|
2020
|
+
const context = getTrajectoryContext();
|
|
2021
|
+
if (context?.trajectoryStepId) {
|
|
2022
|
+
return originalUseModel.call(this, ...args);
|
|
2023
|
+
}
|
|
2024
|
+
const trajLogger = runtime.getService(TrajectoryLoggerService.serviceType);
|
|
2025
|
+
if (!trajLogger || !trajLogger.isEnabled()) {
|
|
2026
|
+
return originalUseModel.call(this, ...args);
|
|
2027
|
+
}
|
|
2028
|
+
const stepId = await trajLogger.startTrajectory(runtime.agentId, {
|
|
2029
|
+
source: "chat-orphan",
|
|
2030
|
+
metadata: { autoPatch: true }
|
|
2031
|
+
});
|
|
2032
|
+
try {
|
|
2033
|
+
return await runWithTrajectoryContext({ trajectoryStepId: stepId }, () => originalUseModel.call(this, ...args));
|
|
2034
|
+
} finally {
|
|
2035
|
+
await trajLogger.endTrajectory(stepId, "completed");
|
|
2036
|
+
}
|
|
2037
|
+
};
|
|
2038
|
+
runtime.useModel = patchedUseModel;
|
|
2039
|
+
}
|
|
114
2040
|
this.initialized = true;
|
|
115
|
-
|
|
2041
|
+
logger2.info("[trajectory-logger] Trajectory logger service initialized");
|
|
116
2042
|
}
|
|
117
2043
|
async getTableColumnNames(tableName) {
|
|
118
2044
|
const names = new Set;
|
|
@@ -124,9 +2050,9 @@ class TrajectoryLoggerService extends Service {
|
|
|
124
2050
|
AND table_schema NOT IN ('pg_catalog', 'information_schema')
|
|
125
2051
|
`);
|
|
126
2052
|
for (const row of result.rows) {
|
|
127
|
-
const
|
|
128
|
-
if (
|
|
129
|
-
names.add(
|
|
2053
|
+
const name2 = asString(pickCell(row, "column_name"));
|
|
2054
|
+
if (name2)
|
|
2055
|
+
names.add(name2);
|
|
130
2056
|
}
|
|
131
2057
|
if (names.size > 0)
|
|
132
2058
|
return names;
|
|
@@ -137,9 +2063,9 @@ class TrajectoryLoggerService extends Service {
|
|
|
137
2063
|
try {
|
|
138
2064
|
const pragma = await this.executeRawSql(`PRAGMA table_info(${safeTableName})`);
|
|
139
2065
|
for (const row of pragma.rows) {
|
|
140
|
-
const
|
|
141
|
-
if (
|
|
142
|
-
names.add(
|
|
2066
|
+
const name2 = asString(pickCell(row, "name"));
|
|
2067
|
+
if (name2)
|
|
2068
|
+
names.add(name2);
|
|
143
2069
|
}
|
|
144
2070
|
} catch {}
|
|
145
2071
|
return names;
|
|
@@ -179,7 +2105,7 @@ class TrajectoryLoggerService extends Service {
|
|
|
179
2105
|
if (combinedMessage.includes("already exists") || combinedMessage.includes("duplicate column") || combinedMessage.includes("duplicate_column")) {
|
|
180
2106
|
continue;
|
|
181
2107
|
}
|
|
182
|
-
|
|
2108
|
+
logger2.warn(`[trajectory-logger] Failed to add trajectories.${columnName} (non-fatal): ${errPlain instanceof Error ? errPlain.message : String(errPlain)}`);
|
|
183
2109
|
}
|
|
184
2110
|
}
|
|
185
2111
|
}
|
|
@@ -240,7 +2166,7 @@ class TrajectoryLoggerService extends Service {
|
|
|
240
2166
|
await this.executeRawSql(`CREATE INDEX IF NOT EXISTS idx_trajectories_batch_id ON trajectories(batch_id)`);
|
|
241
2167
|
await this.executeRawSql(`CREATE INDEX IF NOT EXISTS idx_trajectories_is_training ON trajectories(is_training_data)`);
|
|
242
2168
|
} catch (e) {
|
|
243
|
-
|
|
2169
|
+
logger2.warn(`[trajectory-logger] Failed to create indexes (non-fatal): ${e instanceof Error ? e.message : String(e)}`);
|
|
244
2170
|
}
|
|
245
2171
|
await this.executeRawSql(`
|
|
246
2172
|
CREATE TABLE IF NOT EXISTS trajectory_step_index (
|
|
@@ -296,13 +2222,13 @@ class TrajectoryLoggerService extends Service {
|
|
|
296
2222
|
});
|
|
297
2223
|
}
|
|
298
2224
|
if (fixed > 0) {
|
|
299
|
-
|
|
2225
|
+
logger2.info(`[trajectory-logger] Backfilled ${fixed} completed trajectories with synthetic LLM calls`);
|
|
300
2226
|
}
|
|
301
2227
|
if (rows.rows.length >= maxRows) {
|
|
302
|
-
|
|
2228
|
+
logger2.warn(`[trajectory-logger] Backfill hit safety cap (${maxRows}); remaining older trajectories will be fixed lazily when touched`);
|
|
303
2229
|
}
|
|
304
2230
|
} catch (err) {
|
|
305
|
-
|
|
2231
|
+
logger2.warn(`[trajectory-logger] Failed to backfill trajectories missing LLM calls (non-fatal): ${err instanceof Error ? err.message : String(err)}`);
|
|
306
2232
|
}
|
|
307
2233
|
}
|
|
308
2234
|
normalizePurpose(value) {
|
|
@@ -540,7 +2466,7 @@ class TrajectoryLoggerService extends Service {
|
|
|
540
2466
|
updated_at = ${sqlLiteral(updatedAtIso)}
|
|
541
2467
|
WHERE id = ${sqlLiteral(trajectoryId)}
|
|
542
2468
|
`).catch((legacyErr) => {
|
|
543
|
-
|
|
2469
|
+
logger2.warn({ err: legacyErr, trajectoryId }, `[trajectory-logger] Failed to persist trajectory update after compatibility fallback: ${modernErr instanceof Error ? modernErr.message : String(modernErr)}`);
|
|
544
2470
|
throw legacyErr;
|
|
545
2471
|
});
|
|
546
2472
|
}
|
|
@@ -564,16 +2490,34 @@ class TrajectoryLoggerService extends Service {
|
|
|
564
2490
|
logLlmCall(params) {
|
|
565
2491
|
if (!this.enabled)
|
|
566
2492
|
return;
|
|
2493
|
+
if (shouldSuppressNoInputEmbeddingCall(params))
|
|
2494
|
+
return;
|
|
2495
|
+
const orchestratorCtx = readOrchestratorTrajectoryContext(this.runtime);
|
|
567
2496
|
(async () => {
|
|
568
2497
|
const trajectoryId = await this.resolveTrajectoryId(params.stepId);
|
|
569
2498
|
if (!trajectoryId) {
|
|
570
|
-
|
|
2499
|
+
logger2.debug({ stepId: params.stepId }, "[trajectory-logger] No trajectory mapping for LLM call");
|
|
571
2500
|
return;
|
|
572
2501
|
}
|
|
573
2502
|
await this.withTrajectoryWriteLock(trajectoryId, async () => {
|
|
574
2503
|
const trajectory = await this.getTrajectoryById(trajectoryId);
|
|
575
2504
|
if (!trajectory)
|
|
576
2505
|
return;
|
|
2506
|
+
if (orchestratorCtx) {
|
|
2507
|
+
trajectory.source = "orchestrator";
|
|
2508
|
+
if (!trajectory.metadata)
|
|
2509
|
+
trajectory.metadata = {};
|
|
2510
|
+
trajectory.metadata.orchestrator = { ...orchestratorCtx };
|
|
2511
|
+
}
|
|
2512
|
+
const fullResponse = String(params.response || "");
|
|
2513
|
+
const purposeText = orchestratorCtx?.decisionType ?? String(params.purpose || "action");
|
|
2514
|
+
const insights = extractInsightsFromResponse(fullResponse, purposeText);
|
|
2515
|
+
if (insights.length > 0) {
|
|
2516
|
+
if (!trajectory.metadata)
|
|
2517
|
+
trajectory.metadata = {};
|
|
2518
|
+
const existing = Array.isArray(trajectory.metadata.insights) ? trajectory.metadata.insights : [];
|
|
2519
|
+
trajectory.metadata.insights = [...existing, ...insights].slice(-20);
|
|
2520
|
+
}
|
|
577
2521
|
const step = await this.ensureStepExists(trajectory, params.stepId);
|
|
578
2522
|
const llmCall = {
|
|
579
2523
|
callId: uuidv4(),
|
|
@@ -586,17 +2530,27 @@ class TrajectoryLoggerService extends Service {
|
|
|
586
2530
|
reasoning: params.reasoning,
|
|
587
2531
|
temperature: params.temperature,
|
|
588
2532
|
maxTokens: params.maxTokens,
|
|
589
|
-
purpose: this.normalizePurpose(
|
|
590
|
-
actionType: params.actionType,
|
|
2533
|
+
purpose: this.normalizePurpose(purposeText),
|
|
2534
|
+
actionType: orchestratorCtx ? "orchestrator.useModel" : params.actionType || "runtime.useModel",
|
|
591
2535
|
promptTokens: params.promptTokens,
|
|
592
2536
|
completionTokens: params.completionTokens,
|
|
593
2537
|
latencyMs: params.latencyMs
|
|
594
2538
|
};
|
|
595
2539
|
step.llmCalls.push(llmCall);
|
|
2540
|
+
trajectory.startTime = Math.min(trajectory.startTime, llmCall.timestamp);
|
|
2541
|
+
trajectory.endTime = Math.max(trajectory.endTime ?? llmCall.timestamp, llmCall.timestamp);
|
|
596
2542
|
await this.persistTrajectory(trajectoryId, trajectory, "active");
|
|
2543
|
+
if (!orchestratorCtx && trajectory.source === "chat" && shouldRunObservationExtraction(this.runtime)) {
|
|
2544
|
+
this.pushChatExchange({
|
|
2545
|
+
userPrompt: String(params.userPrompt ?? ""),
|
|
2546
|
+
response: fullResponse,
|
|
2547
|
+
trajectoryId,
|
|
2548
|
+
timestamp: llmCall.timestamp
|
|
2549
|
+
});
|
|
2550
|
+
}
|
|
597
2551
|
});
|
|
598
2552
|
})().catch((err) => {
|
|
599
|
-
|
|
2553
|
+
logger2.warn({ err, stepId: params.stepId }, "[trajectory-logger] Failed to persist LLM call");
|
|
600
2554
|
});
|
|
601
2555
|
}
|
|
602
2556
|
logLLMCall(stepId, details) {
|
|
@@ -630,7 +2584,7 @@ class TrajectoryLoggerService extends Service {
|
|
|
630
2584
|
(async () => {
|
|
631
2585
|
const trajectoryId = await this.resolveTrajectoryId(params.stepId);
|
|
632
2586
|
if (!trajectoryId) {
|
|
633
|
-
|
|
2587
|
+
logger2.debug({ stepId: params.stepId }, "[trajectory-logger] No trajectory mapping for provider access");
|
|
634
2588
|
return;
|
|
635
2589
|
}
|
|
636
2590
|
await this.withTrajectoryWriteLock(trajectoryId, async () => {
|
|
@@ -650,13 +2604,13 @@ class TrajectoryLoggerService extends Service {
|
|
|
650
2604
|
await this.persistTrajectory(trajectoryId, trajectory, "active");
|
|
651
2605
|
});
|
|
652
2606
|
})().catch((err) => {
|
|
653
|
-
|
|
2607
|
+
logger2.warn({ err, stepId: params.stepId }, "[trajectory-logger] Failed to persist provider access");
|
|
654
2608
|
});
|
|
655
2609
|
}
|
|
656
2610
|
logProviderAccessByTrajectoryId(trajectoryId, access) {
|
|
657
2611
|
const stepId = this.getCurrentStepId(trajectoryId);
|
|
658
2612
|
if (!stepId) {
|
|
659
|
-
|
|
2613
|
+
logger2.debug({ trajectoryId }, "[trajectory-logger] No active step for provider access by trajectory");
|
|
660
2614
|
return;
|
|
661
2615
|
}
|
|
662
2616
|
this.logProviderAccess(stepId, access);
|
|
@@ -743,7 +2697,7 @@ class TrajectoryLoggerService extends Service {
|
|
|
743
2697
|
`);
|
|
744
2698
|
persistedStart = true;
|
|
745
2699
|
} catch (legacyErr) {
|
|
746
|
-
|
|
2700
|
+
logger2.warn({ err: legacyErr, trajectoryId }, "[trajectory-logger] Failed to persist trajectory start");
|
|
747
2701
|
}
|
|
748
2702
|
}
|
|
749
2703
|
if (persistedStart && legacyStepId) {
|
|
@@ -751,7 +2705,7 @@ class TrajectoryLoggerService extends Service {
|
|
|
751
2705
|
try {
|
|
752
2706
|
await this.setStepIndex(legacyStepId, trajectoryId, -1, false);
|
|
753
2707
|
} catch (indexErr) {
|
|
754
|
-
|
|
2708
|
+
logger2.warn({ err: indexErr, trajectoryId, stepId: legacyStepId }, "[trajectory-logger] Failed to persist step index for trajectory start");
|
|
755
2709
|
}
|
|
756
2710
|
}
|
|
757
2711
|
return trajectoryId;
|
|
@@ -765,7 +2719,7 @@ class TrajectoryLoggerService extends Service {
|
|
|
765
2719
|
this.withTrajectoryWriteLock(trajectoryId, async () => {
|
|
766
2720
|
const trajectory = await this.getTrajectoryById(trajectoryId);
|
|
767
2721
|
if (!trajectory) {
|
|
768
|
-
|
|
2722
|
+
logger2.warn({ trajectoryId }, "[trajectory-logger] Trajectory not found for startStep");
|
|
769
2723
|
return;
|
|
770
2724
|
}
|
|
771
2725
|
const step = this.createStep(stepId, trajectory.steps.length, envState);
|
|
@@ -774,7 +2728,7 @@ class TrajectoryLoggerService extends Service {
|
|
|
774
2728
|
await this.setStepIndex(stepId, trajectoryId, step.stepNumber, true);
|
|
775
2729
|
await this.persistTrajectory(trajectoryId, trajectory, "active");
|
|
776
2730
|
}).catch((err) => {
|
|
777
|
-
|
|
2731
|
+
logger2.warn({ err, trajectoryId, stepId }, "[trajectory-logger] Failed to persist startStep");
|
|
778
2732
|
});
|
|
779
2733
|
return stepId;
|
|
780
2734
|
}
|
|
@@ -814,7 +2768,7 @@ class TrajectoryLoggerService extends Service {
|
|
|
814
2768
|
this.activeStepIds.delete(trajectoryId);
|
|
815
2769
|
await this.persistTrajectory(trajectoryId, trajectory, "active");
|
|
816
2770
|
}).catch((err) => {
|
|
817
|
-
|
|
2771
|
+
logger2.warn({ err, trajectoryId }, "[trajectory-logger] Failed to complete step");
|
|
818
2772
|
});
|
|
819
2773
|
}
|
|
820
2774
|
async endTrajectory(stepIdOrTrajectoryId, status = "completed", finalMetrics) {
|
|
@@ -822,13 +2776,13 @@ class TrajectoryLoggerService extends Service {
|
|
|
822
2776
|
return;
|
|
823
2777
|
const trajectoryId = await this.resolveTrajectoryId(stepIdOrTrajectoryId);
|
|
824
2778
|
if (!trajectoryId) {
|
|
825
|
-
|
|
2779
|
+
logger2.debug({ stepIdOrTrajectoryId }, "[trajectory-logger] No trajectory to end");
|
|
826
2780
|
return;
|
|
827
2781
|
}
|
|
828
2782
|
await this.withTrajectoryWriteLock(trajectoryId, async () => {
|
|
829
2783
|
const trajectory = await this.getTrajectoryById(trajectoryId);
|
|
830
2784
|
if (!trajectory) {
|
|
831
|
-
|
|
2785
|
+
logger2.debug({ trajectoryId }, "[trajectory-logger] Trajectory not found while ending");
|
|
832
2786
|
return;
|
|
833
2787
|
}
|
|
834
2788
|
const now = Date.now();
|
|
@@ -1041,9 +2995,9 @@ class TrajectoryLoggerService extends Service {
|
|
|
1041
2995
|
if (!runtime?.adapter)
|
|
1042
2996
|
return 0;
|
|
1043
2997
|
const countResult = await this.executeRawSql(`SELECT count(*)::int AS cnt FROM trajectories`);
|
|
1044
|
-
const
|
|
2998
|
+
const count2 = asNumber(pickCell(countResult.rows[0] ?? {}, "cnt")) ?? 0;
|
|
1045
2999
|
await this.executeRawSql(`DELETE FROM trajectories`);
|
|
1046
|
-
return
|
|
3000
|
+
return count2;
|
|
1047
3001
|
}
|
|
1048
3002
|
sanitizeZipFolderName(value) {
|
|
1049
3003
|
const sanitized = value.trim().replace(/[^a-zA-Z0-9._-]+/g, "_").replace(/^_+|_+$/g, "");
|
|
@@ -1192,7 +3146,7 @@ class TrajectoryLoggerService extends Service {
|
|
|
1192
3146
|
t.endTime,
|
|
1193
3147
|
t.durationMs,
|
|
1194
3148
|
t.steps.length,
|
|
1195
|
-
t.steps.reduce((
|
|
3149
|
+
t.steps.reduce((sum2, s) => sum2 + s.llmCalls.length, 0),
|
|
1196
3150
|
t.totalReward,
|
|
1197
3151
|
t.scenarioId ?? ""
|
|
1198
3152
|
].join(","));
|
|
@@ -1261,13 +3215,92 @@ class TrajectoryLoggerService extends Service {
|
|
|
1261
3215
|
return [];
|
|
1262
3216
|
}
|
|
1263
3217
|
}
|
|
3218
|
+
function extractInsightsFromResponse(response, purpose) {
|
|
3219
|
+
const insights = [];
|
|
3220
|
+
const decisionPattern = /DECISION:\s*(.+?)(?:\n|$)/gi;
|
|
3221
|
+
let match;
|
|
3222
|
+
match = decisionPattern.exec(response);
|
|
3223
|
+
while (match !== null) {
|
|
3224
|
+
insights.push(match[1].trim());
|
|
3225
|
+
match = decisionPattern.exec(response);
|
|
3226
|
+
}
|
|
3227
|
+
const keyDecisionPattern = /"keyDecision"\s*:\s*"([^"]+)"/g;
|
|
3228
|
+
match = keyDecisionPattern.exec(response);
|
|
3229
|
+
while (match !== null) {
|
|
3230
|
+
insights.push(match[1].trim());
|
|
3231
|
+
match = keyDecisionPattern.exec(response);
|
|
3232
|
+
}
|
|
3233
|
+
if ((purpose === "turn-complete" || purpose === "coordination") && insights.length === 0) {
|
|
3234
|
+
const reasoningMatch = response.match(/"reasoning"\s*:\s*"([^"]{20,200})"/);
|
|
3235
|
+
if (reasoningMatch)
|
|
3236
|
+
insights.push(reasoningMatch[1].trim());
|
|
3237
|
+
}
|
|
3238
|
+
return insights;
|
|
3239
|
+
}
|
|
3240
|
+
function readOrchestratorTrajectoryContext(runtime) {
|
|
3241
|
+
if (!runtime || typeof runtime !== "object")
|
|
3242
|
+
return;
|
|
3243
|
+
const ctx = runtime.__orchestratorTrajectoryCtx;
|
|
3244
|
+
if (!ctx || typeof ctx !== "object")
|
|
3245
|
+
return;
|
|
3246
|
+
const candidate = ctx;
|
|
3247
|
+
if (candidate.source !== "orchestrator" || typeof candidate.decisionType !== "string")
|
|
3248
|
+
return;
|
|
3249
|
+
return candidate;
|
|
3250
|
+
}
|
|
3251
|
+
function isNumericVectorString(value) {
|
|
3252
|
+
const trimmed = value.trim();
|
|
3253
|
+
if (trimmed === "[array]")
|
|
3254
|
+
return true;
|
|
3255
|
+
if (!trimmed.startsWith("[") || !trimmed.endsWith("]"))
|
|
3256
|
+
return false;
|
|
3257
|
+
const inner = trimmed.slice(1, -1).trim();
|
|
3258
|
+
if (!inner)
|
|
3259
|
+
return false;
|
|
3260
|
+
const parts = inner.split(",").map((part) => part.trim()).filter((part) => part.length > 0);
|
|
3261
|
+
if (parts.length < 8)
|
|
3262
|
+
return false;
|
|
3263
|
+
const sampleSize = Math.min(parts.length, 16);
|
|
3264
|
+
for (let i = 0;i < sampleSize; i += 1) {
|
|
3265
|
+
const numeric = Number(parts[i]);
|
|
3266
|
+
if (!Number.isFinite(numeric))
|
|
3267
|
+
return false;
|
|
3268
|
+
}
|
|
3269
|
+
return true;
|
|
3270
|
+
}
|
|
3271
|
+
function shouldSuppressNoInputEmbeddingCall(params) {
|
|
3272
|
+
const model = String(params.model || "").toLowerCase();
|
|
3273
|
+
const actionType = String(params.actionType || "").toLowerCase();
|
|
3274
|
+
const purpose = String(params.purpose || "").toLowerCase();
|
|
3275
|
+
const isEmbedding = model.includes("embed") || actionType.includes("embed") || purpose.includes("embed");
|
|
3276
|
+
if (!isEmbedding)
|
|
3277
|
+
return false;
|
|
3278
|
+
const userPrompt = String(params.userPrompt ?? params.input ?? "").trim();
|
|
3279
|
+
if (userPrompt.length > 0)
|
|
3280
|
+
return false;
|
|
3281
|
+
const response = String(params.response || "");
|
|
3282
|
+
if (!response.trim())
|
|
3283
|
+
return true;
|
|
3284
|
+
return isNumericVectorString(response);
|
|
3285
|
+
}
|
|
3286
|
+
function shouldRunObservationExtraction(runtime) {
|
|
3287
|
+
if (typeof runtime.getSetting === "function") {
|
|
3288
|
+
const setting = runtime.getSetting("TRAJECTORY_OBSERVATION_EXTRACTION");
|
|
3289
|
+
if (setting === "true")
|
|
3290
|
+
return true;
|
|
3291
|
+
if (setting === "false")
|
|
3292
|
+
return false;
|
|
3293
|
+
}
|
|
3294
|
+
const hasReflection = Array.isArray(runtime.evaluators) && runtime.evaluators.some((e) => e.name === "REFLECTION" || e.name === "RELATIONSHIP_EXTRACTION");
|
|
3295
|
+
return !hasReflection;
|
|
3296
|
+
}
|
|
1264
3297
|
// action-interceptor.ts
|
|
1265
|
-
import { logger as
|
|
3298
|
+
import { logger as logger3 } from "@elizaos/core";
|
|
1266
3299
|
var trajectoryContexts = new WeakMap;
|
|
1267
3300
|
function setTrajectoryContext(runtime, trajectoryId, trajectoryLogger) {
|
|
1268
3301
|
trajectoryContexts.set(runtime, { trajectoryId, logger: trajectoryLogger });
|
|
1269
3302
|
}
|
|
1270
|
-
function
|
|
3303
|
+
function getTrajectoryContext2(runtime) {
|
|
1271
3304
|
return trajectoryContexts.get(runtime) || null;
|
|
1272
3305
|
}
|
|
1273
3306
|
function clearTrajectoryContext(runtime) {
|
|
@@ -1278,7 +3311,7 @@ function wrapActionWithLogging(action, _trajectoryLogger) {
|
|
|
1278
3311
|
return {
|
|
1279
3312
|
...action,
|
|
1280
3313
|
handler: async (runtime, message, state, options, callback) => {
|
|
1281
|
-
const context =
|
|
3314
|
+
const context = getTrajectoryContext2(runtime);
|
|
1282
3315
|
if (!context) {
|
|
1283
3316
|
const result = await originalHandler(runtime, message, state, options, callback);
|
|
1284
3317
|
return result ?? undefined;
|
|
@@ -1286,7 +3319,7 @@ function wrapActionWithLogging(action, _trajectoryLogger) {
|
|
|
1286
3319
|
const { trajectoryId, logger: loggerService } = context;
|
|
1287
3320
|
const stepId = loggerService.getCurrentStepId(trajectoryId);
|
|
1288
3321
|
if (!stepId) {
|
|
1289
|
-
|
|
3322
|
+
logger3.warn({ action: action.name, trajectoryId }, "No active step for action execution");
|
|
1290
3323
|
const result = await originalHandler(runtime, message, state, options, callback);
|
|
1291
3324
|
return result ?? undefined;
|
|
1292
3325
|
}
|
|
@@ -1306,7 +3339,7 @@ function wrapActionWithLogging(action, _trajectoryLogger) {
|
|
|
1306
3339
|
};
|
|
1307
3340
|
const errorHandler = (err) => {
|
|
1308
3341
|
const error = err instanceof Error ? err.message : typeof err === "string" ? err : err.message || String(err);
|
|
1309
|
-
|
|
3342
|
+
logger3.error({ action: action.name, trajectoryId, error }, "Action execution failed");
|
|
1310
3343
|
const stateSnapshot = state ? JSON.parse(JSON.stringify(state)) : null;
|
|
1311
3344
|
loggerService.completeStep(trajectoryId, stepId, {
|
|
1312
3345
|
actionType: action.name,
|
|
@@ -1349,7 +3382,7 @@ function wrapPluginActions(plugin, trajectoryLogger) {
|
|
|
1349
3382
|
function logLLMCallFromAction(actionContext, trajectoryLogger, trajectoryId) {
|
|
1350
3383
|
const stepId = trajectoryLogger.getCurrentStepId(trajectoryId);
|
|
1351
3384
|
if (!stepId) {
|
|
1352
|
-
|
|
3385
|
+
logger3.warn({ trajectoryId }, "No active step for LLM call from action");
|
|
1353
3386
|
return;
|
|
1354
3387
|
}
|
|
1355
3388
|
trajectoryLogger.logLLMCall(stepId, {
|
|
@@ -1370,7 +3403,7 @@ function logLLMCallFromAction(actionContext, trajectoryLogger, trajectoryId) {
|
|
|
1370
3403
|
function logProviderFromAction(actionContext, trajectoryLogger, trajectoryId) {
|
|
1371
3404
|
const stepId = trajectoryLogger.getCurrentStepId(trajectoryId);
|
|
1372
3405
|
if (!stepId) {
|
|
1373
|
-
|
|
3406
|
+
logger3.warn({ trajectoryId }, "No active step for provider access from action");
|
|
1374
3407
|
return;
|
|
1375
3408
|
}
|
|
1376
3409
|
trajectoryLogger.logProviderAccess(stepId, {
|
|
@@ -1385,14 +3418,14 @@ function wrapProviderWithLogging(provider, _trajectoryLogger) {
|
|
|
1385
3418
|
return {
|
|
1386
3419
|
...provider,
|
|
1387
3420
|
get: async (runtime, message, state) => {
|
|
1388
|
-
const context =
|
|
3421
|
+
const context = getTrajectoryContext2(runtime);
|
|
1389
3422
|
if (!context) {
|
|
1390
3423
|
return originalGet?.(runtime, message, state) || { text: "" };
|
|
1391
3424
|
}
|
|
1392
3425
|
const { trajectoryId, logger: loggerService } = context;
|
|
1393
3426
|
const stepId = loggerService.getCurrentStepId(trajectoryId);
|
|
1394
3427
|
if (!stepId) {
|
|
1395
|
-
|
|
3428
|
+
logger3.warn({ provider: provider.name, trajectoryId }, "No active step for provider access");
|
|
1396
3429
|
return originalGet?.(runtime, message, state) || { text: "" };
|
|
1397
3430
|
}
|
|
1398
3431
|
const result = await originalGet?.(runtime, message, state) || { text: "" };
|
|
@@ -1594,14 +3627,14 @@ function toARTJSONL(trajectory) {
|
|
|
1594
3627
|
return JSON.stringify(toARTTrajectory(trajectory));
|
|
1595
3628
|
}
|
|
1596
3629
|
function validateARTCompatibility(trajectory) {
|
|
1597
|
-
const
|
|
3630
|
+
const errors2 = [];
|
|
1598
3631
|
const warnings = [];
|
|
1599
3632
|
if (trajectory.steps.length === 0) {
|
|
1600
|
-
|
|
3633
|
+
errors2.push("Trajectory has no steps");
|
|
1601
3634
|
}
|
|
1602
3635
|
for (const [idx, step] of trajectory.steps.entries()) {
|
|
1603
3636
|
if (step.llmCalls.length === 0) {
|
|
1604
|
-
|
|
3637
|
+
errors2.push(`Step ${idx} has no LLM calls - can't extract messages`);
|
|
1605
3638
|
}
|
|
1606
3639
|
for (const llmCall of step.llmCalls) {
|
|
1607
3640
|
if (!llmCall.userPrompt || llmCall.userPrompt.length < 10) {
|
|
@@ -1613,15 +3646,15 @@ function validateARTCompatibility(trajectory) {
|
|
|
1613
3646
|
}
|
|
1614
3647
|
}
|
|
1615
3648
|
if (trajectory.totalReward === undefined || Number.isNaN(trajectory.totalReward)) {
|
|
1616
|
-
|
|
3649
|
+
errors2.push("Trajectory has no valid reward");
|
|
1617
3650
|
}
|
|
1618
3651
|
const artTraj = toARTTrajectory(trajectory);
|
|
1619
3652
|
if (artTraj.messages.length < 2) {
|
|
1620
3653
|
warnings.push("Trajectory converts to very few messages (< 2)");
|
|
1621
3654
|
}
|
|
1622
3655
|
return {
|
|
1623
|
-
valid:
|
|
1624
|
-
errors,
|
|
3656
|
+
valid: errors2.length === 0,
|
|
3657
|
+
errors: errors2,
|
|
1625
3658
|
warnings
|
|
1626
3659
|
};
|
|
1627
3660
|
}
|
|
@@ -1717,7 +3750,7 @@ async function buildGameStateFromDB(_trajectoryId) {
|
|
|
1717
3750
|
}
|
|
1718
3751
|
async function recomputeTrajectoryRewards(_trajectoryIds) {}
|
|
1719
3752
|
// integration.ts
|
|
1720
|
-
import { logger as
|
|
3753
|
+
import { logger as logger4 } from "@elizaos/core";
|
|
1721
3754
|
async function startAutonomousTick(trajectoryLogger, context) {
|
|
1722
3755
|
const trajectoryId = await trajectoryLogger.startTrajectory(context.agentId, {
|
|
1723
3756
|
scenarioId: context.scenarioId,
|
|
@@ -1733,17 +3766,17 @@ async function startAutonomousTick(trajectoryLogger, context) {
|
|
|
1733
3766
|
openPositions: 0
|
|
1734
3767
|
};
|
|
1735
3768
|
trajectoryLogger.startStep(trajectoryId, envState);
|
|
1736
|
-
|
|
3769
|
+
logger4.info({ trajectoryId, agentId: context.agentId }, "Started autonomous tick trajectory");
|
|
1737
3770
|
return trajectoryId;
|
|
1738
3771
|
}
|
|
1739
3772
|
async function endAutonomousTick(trajectoryLogger, trajectoryId, status = "completed", finalMetrics) {
|
|
1740
3773
|
await trajectoryLogger.endTrajectory(trajectoryId, status, finalMetrics);
|
|
1741
|
-
|
|
3774
|
+
logger4.info({ trajectoryId, status }, "Ended autonomous tick trajectory");
|
|
1742
3775
|
}
|
|
1743
3776
|
async function loggedLLMCall(trajectoryLogger, trajectoryId, options, llmCallFn) {
|
|
1744
3777
|
const stepId = trajectoryLogger.getCurrentStepId(trajectoryId);
|
|
1745
3778
|
if (!stepId) {
|
|
1746
|
-
|
|
3779
|
+
logger4.warn({ trajectoryId }, "No active step for LLM call");
|
|
1747
3780
|
const result2 = await llmCallFn();
|
|
1748
3781
|
return result2.text;
|
|
1749
3782
|
}
|
|
@@ -1848,13 +3881,13 @@ class RewardService {
|
|
|
1848
3881
|
return (score + 1) / 2;
|
|
1849
3882
|
}
|
|
1850
3883
|
normalizeScoresForGroup(scores) {
|
|
1851
|
-
const
|
|
1852
|
-
const
|
|
1853
|
-
const range =
|
|
3884
|
+
const min2 = Math.min(...scores);
|
|
3885
|
+
const max2 = Math.max(...scores);
|
|
3886
|
+
const range = max2 - min2;
|
|
1854
3887
|
if (range === 0) {
|
|
1855
3888
|
return scores.map(() => 0.5);
|
|
1856
3889
|
}
|
|
1857
|
-
return scores.map((s) => (s -
|
|
3890
|
+
return scores.map((s) => (s - min2) / range);
|
|
1858
3891
|
}
|
|
1859
3892
|
}
|
|
1860
3893
|
function createRewardService(options = {}) {
|
|
@@ -1889,13 +3922,13 @@ var trajectoryLoggerPlugin = {
|
|
|
1889
3922
|
};
|
|
1890
3923
|
}
|
|
1891
3924
|
const meta = message.metadata;
|
|
1892
|
-
const
|
|
1893
|
-
if (!
|
|
3925
|
+
const logger5 = runtime.getService("trajectory_logger");
|
|
3926
|
+
if (!logger5)
|
|
1894
3927
|
return;
|
|
1895
3928
|
let trajectoryStepId = crypto.randomUUID();
|
|
1896
3929
|
meta.trajectoryStepId = trajectoryStepId;
|
|
1897
3930
|
try {
|
|
1898
|
-
const trajectoryId = await
|
|
3931
|
+
const trajectoryId = await logger5.startTrajectory(runtime.agentId, {
|
|
1899
3932
|
source: source ?? meta.source ?? "chat",
|
|
1900
3933
|
metadata: {
|
|
1901
3934
|
roomId: message.roomId,
|
|
@@ -1907,7 +3940,7 @@ var trajectoryLoggerPlugin = {
|
|
|
1907
3940
|
});
|
|
1908
3941
|
const normalizedTrajectoryId = typeof trajectoryId === "string" && trajectoryId.trim().length > 0 ? trajectoryId : null;
|
|
1909
3942
|
if (normalizedTrajectoryId) {
|
|
1910
|
-
const runtimeStepId =
|
|
3943
|
+
const runtimeStepId = logger5.startStep(normalizedTrajectoryId, {
|
|
1911
3944
|
timestamp: Date.now(),
|
|
1912
3945
|
agentBalance: 0,
|
|
1913
3946
|
agentPoints: 0,
|
|
@@ -1945,12 +3978,12 @@ var trajectoryLoggerPlugin = {
|
|
|
1945
3978
|
}
|
|
1946
3979
|
if (!trajectoryStepId)
|
|
1947
3980
|
return;
|
|
1948
|
-
const
|
|
1949
|
-
if (!
|
|
3981
|
+
const logger5 = runtime.getService("trajectory_logger");
|
|
3982
|
+
if (!logger5)
|
|
1950
3983
|
return;
|
|
1951
3984
|
try {
|
|
1952
3985
|
const endTarget = pendingTrajectoryEndTargetByStepId.get(trajectoryStepId) ?? trajectoryStepId;
|
|
1953
|
-
await
|
|
3986
|
+
await logger5.endTrajectory(endTarget, "completed");
|
|
1954
3987
|
} catch (err) {
|
|
1955
3988
|
runtime.logger?.warn({
|
|
1956
3989
|
err,
|
|
@@ -1990,7 +4023,7 @@ export {
|
|
|
1990
4023
|
logProviderAccess,
|
|
1991
4024
|
logLLMCallFromAction,
|
|
1992
4025
|
groupTrajectories,
|
|
1993
|
-
getTrajectoryContext,
|
|
4026
|
+
getTrajectoryContext2 as getTrajectoryContext,
|
|
1994
4027
|
extractSharedPrefix,
|
|
1995
4028
|
exportToHuggingFace,
|
|
1996
4029
|
exportGroupedForGRPO,
|
|
@@ -2007,4 +4040,4 @@ export {
|
|
|
2007
4040
|
RewardService
|
|
2008
4041
|
};
|
|
2009
4042
|
|
|
2010
|
-
//# debugId=
|
|
4043
|
+
//# debugId=07960868DB73CC4E64756E2164756E21
|