@exulu/backend 0.1.7 → 0.1.9
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/index.cjs +36 -2
- package/dist/index.js +36 -2
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -113,6 +113,12 @@ var import_knex3 = require("pgvector/knex");
|
|
|
113
113
|
var db = {};
|
|
114
114
|
async function postgresClient() {
|
|
115
115
|
if (!db["exulu"]) {
|
|
116
|
+
console.log("[EXULU] Initializing exulu database.");
|
|
117
|
+
console.log(process.env.POSTGRES_DB_HOST);
|
|
118
|
+
console.log(process.env.POSTGRES_DB_PORT);
|
|
119
|
+
console.log(process.env.POSTGRES_DB_USER);
|
|
120
|
+
console.log(process.env.POSTGRES_DB_PASSWORD);
|
|
121
|
+
console.log(process.env.POSTGRES_DB_SSL);
|
|
116
122
|
const knex = (0, import_knex.default)({
|
|
117
123
|
client: "pg",
|
|
118
124
|
connection: {
|
|
@@ -392,6 +398,7 @@ var sanitizeName = (name) => {
|
|
|
392
398
|
};
|
|
393
399
|
|
|
394
400
|
// src/postgres/init-db.ts
|
|
401
|
+
var import_bcryptjs = __toESM(require("bcryptjs"), 1);
|
|
395
402
|
var up = async function(knex) {
|
|
396
403
|
if (!await knex.schema.hasTable("roles")) {
|
|
397
404
|
await knex.schema.createTable("roles", (table) => {
|
|
@@ -539,6 +546,11 @@ var up = async function(knex) {
|
|
|
539
546
|
});
|
|
540
547
|
}
|
|
541
548
|
};
|
|
549
|
+
var SALT_ROUNDS = 12;
|
|
550
|
+
async function encryptApiKey(apiKey) {
|
|
551
|
+
const hash = await import_bcryptjs.default.hash(apiKey, SALT_ROUNDS);
|
|
552
|
+
return hash;
|
|
553
|
+
}
|
|
542
554
|
var execute = async () => {
|
|
543
555
|
console.log("[EXULU] Initializing database.");
|
|
544
556
|
const { db: db2 } = await postgresClient();
|
|
@@ -557,6 +569,10 @@ var execute = async () => {
|
|
|
557
569
|
} else {
|
|
558
570
|
roleId = existingRole.id;
|
|
559
571
|
}
|
|
572
|
+
const newKeyName = "exulu_default_key";
|
|
573
|
+
const plainKey = `sk_${Math.random().toString(36).substring(2, 15)}_${Math.random().toString(36).substring(2, 15)}`;
|
|
574
|
+
const postFix = `/${newKeyName.toLowerCase().trim().replaceAll(" ", "_")}`;
|
|
575
|
+
const encryptedKey = await encryptApiKey(plainKey);
|
|
560
576
|
const existingUser = await db2.from("users").where({ email: "admin@exulu.com" }).first();
|
|
561
577
|
if (!existingUser) {
|
|
562
578
|
console.log("[EXULU] Creating default admin user.");
|
|
@@ -566,11 +582,28 @@ var execute = async () => {
|
|
|
566
582
|
super_admin: true,
|
|
567
583
|
createdAt: /* @__PURE__ */ new Date(),
|
|
568
584
|
updatedAt: /* @__PURE__ */ new Date(),
|
|
585
|
+
type: "user",
|
|
586
|
+
// password: "admin", todo add this again when we implement password auth / encryption as alternative to OTP
|
|
587
|
+
role: roleId
|
|
588
|
+
});
|
|
589
|
+
}
|
|
590
|
+
const existingApiUser = await db2.from("users").where({ email: "api@exulu.com" }).first();
|
|
591
|
+
if (!existingApiUser) {
|
|
592
|
+
console.log("[EXULU] Creating default api user.");
|
|
593
|
+
await db2.from("users").insert({
|
|
594
|
+
name: "exulu",
|
|
595
|
+
email: "admin@exulu.com",
|
|
596
|
+
super_admin: true,
|
|
597
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
598
|
+
updatedAt: /* @__PURE__ */ new Date(),
|
|
599
|
+
type: "user",
|
|
600
|
+
apikey: `${encryptedKey}${postFix}`,
|
|
569
601
|
// password: "admin", todo add this again when we implement password auth / encryption as alternative to OTP
|
|
570
602
|
role: roleId
|
|
571
603
|
});
|
|
572
604
|
}
|
|
573
605
|
console.log("[EXULU] Database initialized.");
|
|
606
|
+
console.log("[EXULU] Default api key: ", `${encryptedKey}${postFix}`);
|
|
574
607
|
return;
|
|
575
608
|
};
|
|
576
609
|
|
|
@@ -733,6 +766,7 @@ var ExuluAgent = class {
|
|
|
733
766
|
this.capabilities = capabilities;
|
|
734
767
|
this.slug = `/agents/${generateSlug(this.name)}/run`;
|
|
735
768
|
if (config?.memory) {
|
|
769
|
+
console.log("[EXULU] Initializing memory for agent " + this.name);
|
|
736
770
|
const connectionString = `postgresql://${process.env.POSTGRES_DB_USER}:${process.env.POSTGRES_DB_PASSWORD}@${process.env.POSTGRES_DB_HOST}:${process.env.POSTGRES_DB_PORT}/exulu`;
|
|
737
771
|
this.memory = new import_memory.Memory({
|
|
738
772
|
storage: new import_pg.PostgresStore({
|
|
@@ -1421,7 +1455,7 @@ var import_express = require("express");
|
|
|
1421
1455
|
var import_jwt = require("next-auth/jwt");
|
|
1422
1456
|
|
|
1423
1457
|
// src/auth/auth.ts
|
|
1424
|
-
var
|
|
1458
|
+
var import_bcryptjs2 = __toESM(require("bcryptjs"), 1);
|
|
1425
1459
|
var authentication = async ({
|
|
1426
1460
|
apikey,
|
|
1427
1461
|
authtoken,
|
|
@@ -1516,7 +1550,7 @@ var authentication = async ({
|
|
|
1516
1550
|
for (const user of filtered) {
|
|
1517
1551
|
const lastSlashIndex = user.apiKey.lastIndexOf("/");
|
|
1518
1552
|
const compareValue = lastSlashIndex !== -1 ? user.apiKey.substring(0, lastSlashIndex) : user.apiKey;
|
|
1519
|
-
const isMatch = await
|
|
1553
|
+
const isMatch = await import_bcryptjs2.default.compare(keyValue, compareValue);
|
|
1520
1554
|
if (isMatch) {
|
|
1521
1555
|
await db2.from("users").where({ id: user.id }).update({
|
|
1522
1556
|
lastUsed: /* @__PURE__ */ new Date()
|
package/dist/index.js
CHANGED
|
@@ -72,6 +72,12 @@ import "pgvector/knex";
|
|
|
72
72
|
var db = {};
|
|
73
73
|
async function postgresClient() {
|
|
74
74
|
if (!db["exulu"]) {
|
|
75
|
+
console.log("[EXULU] Initializing exulu database.");
|
|
76
|
+
console.log(process.env.POSTGRES_DB_HOST);
|
|
77
|
+
console.log(process.env.POSTGRES_DB_PORT);
|
|
78
|
+
console.log(process.env.POSTGRES_DB_USER);
|
|
79
|
+
console.log(process.env.POSTGRES_DB_PASSWORD);
|
|
80
|
+
console.log(process.env.POSTGRES_DB_SSL);
|
|
75
81
|
const knex = Knex({
|
|
76
82
|
client: "pg",
|
|
77
83
|
connection: {
|
|
@@ -351,6 +357,7 @@ var sanitizeName = (name) => {
|
|
|
351
357
|
};
|
|
352
358
|
|
|
353
359
|
// src/postgres/init-db.ts
|
|
360
|
+
import bcrypt from "bcryptjs";
|
|
354
361
|
var up = async function(knex) {
|
|
355
362
|
if (!await knex.schema.hasTable("roles")) {
|
|
356
363
|
await knex.schema.createTable("roles", (table) => {
|
|
@@ -498,6 +505,11 @@ var up = async function(knex) {
|
|
|
498
505
|
});
|
|
499
506
|
}
|
|
500
507
|
};
|
|
508
|
+
var SALT_ROUNDS = 12;
|
|
509
|
+
async function encryptApiKey(apiKey) {
|
|
510
|
+
const hash = await bcrypt.hash(apiKey, SALT_ROUNDS);
|
|
511
|
+
return hash;
|
|
512
|
+
}
|
|
501
513
|
var execute = async () => {
|
|
502
514
|
console.log("[EXULU] Initializing database.");
|
|
503
515
|
const { db: db2 } = await postgresClient();
|
|
@@ -516,6 +528,10 @@ var execute = async () => {
|
|
|
516
528
|
} else {
|
|
517
529
|
roleId = existingRole.id;
|
|
518
530
|
}
|
|
531
|
+
const newKeyName = "exulu_default_key";
|
|
532
|
+
const plainKey = `sk_${Math.random().toString(36).substring(2, 15)}_${Math.random().toString(36).substring(2, 15)}`;
|
|
533
|
+
const postFix = `/${newKeyName.toLowerCase().trim().replaceAll(" ", "_")}`;
|
|
534
|
+
const encryptedKey = await encryptApiKey(plainKey);
|
|
519
535
|
const existingUser = await db2.from("users").where({ email: "admin@exulu.com" }).first();
|
|
520
536
|
if (!existingUser) {
|
|
521
537
|
console.log("[EXULU] Creating default admin user.");
|
|
@@ -525,11 +541,28 @@ var execute = async () => {
|
|
|
525
541
|
super_admin: true,
|
|
526
542
|
createdAt: /* @__PURE__ */ new Date(),
|
|
527
543
|
updatedAt: /* @__PURE__ */ new Date(),
|
|
544
|
+
type: "user",
|
|
545
|
+
// password: "admin", todo add this again when we implement password auth / encryption as alternative to OTP
|
|
546
|
+
role: roleId
|
|
547
|
+
});
|
|
548
|
+
}
|
|
549
|
+
const existingApiUser = await db2.from("users").where({ email: "api@exulu.com" }).first();
|
|
550
|
+
if (!existingApiUser) {
|
|
551
|
+
console.log("[EXULU] Creating default api user.");
|
|
552
|
+
await db2.from("users").insert({
|
|
553
|
+
name: "exulu",
|
|
554
|
+
email: "admin@exulu.com",
|
|
555
|
+
super_admin: true,
|
|
556
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
557
|
+
updatedAt: /* @__PURE__ */ new Date(),
|
|
558
|
+
type: "user",
|
|
559
|
+
apikey: `${encryptedKey}${postFix}`,
|
|
528
560
|
// password: "admin", todo add this again when we implement password auth / encryption as alternative to OTP
|
|
529
561
|
role: roleId
|
|
530
562
|
});
|
|
531
563
|
}
|
|
532
564
|
console.log("[EXULU] Database initialized.");
|
|
565
|
+
console.log("[EXULU] Default api key: ", `${encryptedKey}${postFix}`);
|
|
533
566
|
return;
|
|
534
567
|
};
|
|
535
568
|
|
|
@@ -692,6 +725,7 @@ var ExuluAgent = class {
|
|
|
692
725
|
this.capabilities = capabilities;
|
|
693
726
|
this.slug = `/agents/${generateSlug(this.name)}/run`;
|
|
694
727
|
if (config?.memory) {
|
|
728
|
+
console.log("[EXULU] Initializing memory for agent " + this.name);
|
|
695
729
|
const connectionString = `postgresql://${process.env.POSTGRES_DB_USER}:${process.env.POSTGRES_DB_PASSWORD}@${process.env.POSTGRES_DB_HOST}:${process.env.POSTGRES_DB_PORT}/exulu`;
|
|
696
730
|
this.memory = new Memory({
|
|
697
731
|
storage: new PostgresStore({
|
|
@@ -1380,7 +1414,7 @@ import "express";
|
|
|
1380
1414
|
import { getToken } from "next-auth/jwt";
|
|
1381
1415
|
|
|
1382
1416
|
// src/auth/auth.ts
|
|
1383
|
-
import
|
|
1417
|
+
import bcrypt2 from "bcryptjs";
|
|
1384
1418
|
var authentication = async ({
|
|
1385
1419
|
apikey,
|
|
1386
1420
|
authtoken,
|
|
@@ -1475,7 +1509,7 @@ var authentication = async ({
|
|
|
1475
1509
|
for (const user of filtered) {
|
|
1476
1510
|
const lastSlashIndex = user.apiKey.lastIndexOf("/");
|
|
1477
1511
|
const compareValue = lastSlashIndex !== -1 ? user.apiKey.substring(0, lastSlashIndex) : user.apiKey;
|
|
1478
|
-
const isMatch = await
|
|
1512
|
+
const isMatch = await bcrypt2.compare(keyValue, compareValue);
|
|
1479
1513
|
if (isMatch) {
|
|
1480
1514
|
await db2.from("users").where({ id: user.id }).update({
|
|
1481
1515
|
lastUsed: /* @__PURE__ */ new Date()
|