@yrpri/api 9.0.91 → 9.0.92
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/active-citizen/engine/allOurIdeas/iconGenerator.js +29 -42
- package/active-citizen/llms/baseChatBot.js +9 -4
- package/active-citizen/llms/collectionImageGenerator.js +27 -30
- package/active-citizen/llms/imageGeneration/collectionImageGenerator.js +103 -0
- package/active-citizen/llms/imageGeneration/dalleImageGenerator.js +83 -0
- package/active-citizen/llms/imageGeneration/fluxImageGenerator.js +49 -0
- package/active-citizen/llms/imageGeneration/iImageGenerator.js +1 -0
- package/active-citizen/llms/imageGeneration/imageProcessorService.js +64 -0
- package/active-citizen/llms/imageGeneration/imagenImageGenerator.js +107 -0
- package/active-citizen/llms/imageGeneration/s3Service.js +110 -0
- package/active-citizen/models/ac_translation_cache.cjs +2 -0
- package/active-citizen/workers/generativeAi.js +1 -1
- package/agents/assistants/baseAssistant.js +38 -25
- package/agents/assistants/baseAssistantWithVoice.js +33 -6
- package/agents/assistants/voiceAssistant.js +31 -3
- package/agents/controllers/agentSubscriptionController.js +21 -16
- package/agents/controllers/assistantsController.js +29 -10
- package/agents/managers/newAiModelSetup.js +3 -0
- package/agents/managers/subscriptionManager.js +2 -2
- package/app.js +4 -130
- package/models/image.cjs +1 -1
- package/models/index.cjs +20 -12
- package/models/video.cjs +1 -1
- package/package.json +28 -27
- package/utils/manifest_generator.cjs +0 -1
- package/utils/sitemap_generator.cjs +6 -0
- package/webSockets.js +346 -0
package/app.js
CHANGED
|
@@ -108,9 +108,8 @@ process.on("unhandledRejection", (reason, promise) => {
|
|
|
108
108
|
}
|
|
109
109
|
});
|
|
110
110
|
import { botsWithJavascript, isBadBot, } from "./bot_control.js";
|
|
111
|
-
import { WebSocketServer } from "ws";
|
|
112
|
-
import { v4 as uuidv4 } from "uuid";
|
|
113
111
|
import { Op } from "sequelize";
|
|
112
|
+
import { WebSocketsManager } from "./webSockets.js";
|
|
114
113
|
export class YourPrioritiesApi {
|
|
115
114
|
constructor(port = undefined) {
|
|
116
115
|
this.determineVersion = (req) => {
|
|
@@ -581,7 +580,6 @@ export class YourPrioritiesApi {
|
|
|
581
580
|
this.app.use((req, res, next) => {
|
|
582
581
|
const baseDir = path.join(__dirname, "../webAppsDist");
|
|
583
582
|
const useNewVersion = req.useNewVersion;
|
|
584
|
-
console.log(`------XY-----------------------> Using new version: ${useNewVersion}`);
|
|
585
583
|
// Set the paths depending on the version
|
|
586
584
|
req.adminAppPath = useNewVersion
|
|
587
585
|
? path.join(baseDir, "client/dist")
|
|
@@ -592,7 +590,7 @@ export class YourPrioritiesApi {
|
|
|
592
590
|
const staticPath = req.path.startsWith("/admin")
|
|
593
591
|
? req.adminAppPath
|
|
594
592
|
: req.clientAppPath;
|
|
595
|
-
console.log("Static path", staticPath);
|
|
593
|
+
//console.log("Static path", staticPath);
|
|
596
594
|
// Check if the request is for index.html
|
|
597
595
|
if (req.path === "/" || req.path === "/index.html") {
|
|
598
596
|
index(req, res, next); // Use your dynamic handler
|
|
@@ -922,132 +920,8 @@ export class YourPrioritiesApi {
|
|
|
922
920
|
}
|
|
923
921
|
async listen() {
|
|
924
922
|
const server = await this.setupHttpsServer();
|
|
925
|
-
|
|
926
|
-
this.
|
|
927
|
-
this.ws.on("connection", (ws) => {
|
|
928
|
-
const clientId = uuidv4();
|
|
929
|
-
this.wsClients.set(clientId, ws);
|
|
930
|
-
console.log(`New WebSocket connection: clientId ${clientId}`);
|
|
931
|
-
ws.send(JSON.stringify({ clientId: clientId }));
|
|
932
|
-
ws.on("message", (message) => {
|
|
933
|
-
let parsedMessage;
|
|
934
|
-
try {
|
|
935
|
-
parsedMessage = JSON.parse(message);
|
|
936
|
-
}
|
|
937
|
-
catch (e) {
|
|
938
|
-
console.log(`Received non-JSON message from client ${clientId}:`, message);
|
|
939
|
-
parsedMessage = message;
|
|
940
|
-
}
|
|
941
|
-
if (parsedMessage && parsedMessage.type === "heartbeat") {
|
|
942
|
-
console.log(`Received heartbeat from client ${clientId}`);
|
|
943
|
-
ws.send(JSON.stringify({ type: "heartbeat_ack" }));
|
|
944
|
-
}
|
|
945
|
-
else if (!this.wsClients.has(clientId)) {
|
|
946
|
-
const messageToSend = JSON.stringify({
|
|
947
|
-
clientId,
|
|
948
|
-
action: "directMessage",
|
|
949
|
-
data: parsedMessage,
|
|
950
|
-
});
|
|
951
|
-
pub
|
|
952
|
-
.publish("ypWebsocketChannel", messageToSend)
|
|
953
|
-
.then((reply) => {
|
|
954
|
-
console.log(`Message published to ypWebsocketChannel: ${reply}`);
|
|
955
|
-
})
|
|
956
|
-
.catch((err) => {
|
|
957
|
-
console.error(`Error publishing to Redis channel ypWebsocketChannel:`, err);
|
|
958
|
-
});
|
|
959
|
-
}
|
|
960
|
-
});
|
|
961
|
-
ws.on("close", () => {
|
|
962
|
-
this.wsClients.delete(clientId);
|
|
963
|
-
console.log(`WebSocket connection closed: clientId ${clientId}`);
|
|
964
|
-
});
|
|
965
|
-
ws.on("error", (err) => {
|
|
966
|
-
this.wsClients.delete(clientId);
|
|
967
|
-
console.error(`WebSocket error with clientId ${clientId}:`, err);
|
|
968
|
-
});
|
|
969
|
-
});
|
|
970
|
-
}
|
|
971
|
-
async setupPubSub() {
|
|
972
|
-
const pub = this.redisClient.duplicate();
|
|
973
|
-
const sub = this.redisClient.duplicate();
|
|
974
|
-
pub.on("error", (err) => {
|
|
975
|
-
console.error("Publisher Redis client error:", err);
|
|
976
|
-
});
|
|
977
|
-
pub.on("connect", () => {
|
|
978
|
-
console.log("Publisher Redis client is connected");
|
|
979
|
-
});
|
|
980
|
-
pub.on("reconnecting", () => {
|
|
981
|
-
console.log("Publisher Redis client is reconnecting");
|
|
982
|
-
});
|
|
983
|
-
sub.on("error", (err) => {
|
|
984
|
-
console.error("Subscriber Redis client error:", err);
|
|
985
|
-
});
|
|
986
|
-
sub.on("connect", () => {
|
|
987
|
-
console.log("Subscriber Redis client is connected");
|
|
988
|
-
});
|
|
989
|
-
sub.on("reconnecting", () => {
|
|
990
|
-
console.log("Subscriber Redis client is reconnecting");
|
|
991
|
-
});
|
|
992
|
-
try {
|
|
993
|
-
await Promise.all([pub.connect(), sub.connect()]);
|
|
994
|
-
}
|
|
995
|
-
catch (err) {
|
|
996
|
-
console.error("Error connecting to Redis:", err);
|
|
997
|
-
}
|
|
998
|
-
sub.subscribe("ypWebsocketChannel", (message, channel) => {
|
|
999
|
-
try {
|
|
1000
|
-
const parsedMessage = JSON.parse(message);
|
|
1001
|
-
const { clientId, action, data } = parsedMessage;
|
|
1002
|
-
console.log(`Received message from Redis: ${message} at ${channel}`);
|
|
1003
|
-
switch (action) {
|
|
1004
|
-
case "broadcast":
|
|
1005
|
-
this.wsClients.forEach((ws, id) => {
|
|
1006
|
-
try {
|
|
1007
|
-
ws.send(JSON.stringify(data));
|
|
1008
|
-
}
|
|
1009
|
-
catch (err) {
|
|
1010
|
-
console.error(`Error sending broadcast message to client ${id}:`, err);
|
|
1011
|
-
}
|
|
1012
|
-
});
|
|
1013
|
-
break;
|
|
1014
|
-
case "directMessage":
|
|
1015
|
-
const ws = this.wsClients.get(clientId);
|
|
1016
|
-
if (ws) {
|
|
1017
|
-
try {
|
|
1018
|
-
ws.send(JSON.stringify(data));
|
|
1019
|
-
}
|
|
1020
|
-
catch (err) {
|
|
1021
|
-
console.error(`Error sending direct message to client ${clientId}:`, err);
|
|
1022
|
-
}
|
|
1023
|
-
}
|
|
1024
|
-
else {
|
|
1025
|
-
console.warn(`No WebSocket found for clientId ${clientId}`);
|
|
1026
|
-
this.wsClients.delete(clientId);
|
|
1027
|
-
}
|
|
1028
|
-
break;
|
|
1029
|
-
}
|
|
1030
|
-
}
|
|
1031
|
-
catch (e) {
|
|
1032
|
-
console.error("Error handling message from Redis:", e);
|
|
1033
|
-
}
|
|
1034
|
-
});
|
|
1035
|
-
return [pub, sub];
|
|
1036
|
-
}
|
|
1037
|
-
handleLocalMessage(clientId, parsedMessage) {
|
|
1038
|
-
const ws = this.wsClients.get(clientId);
|
|
1039
|
-
if (ws) {
|
|
1040
|
-
try {
|
|
1041
|
-
ws.send(parsedMessage);
|
|
1042
|
-
}
|
|
1043
|
-
catch (err) {
|
|
1044
|
-
console.error(`Error sending message to client ${clientId}:`, err);
|
|
1045
|
-
}
|
|
1046
|
-
}
|
|
1047
|
-
else {
|
|
1048
|
-
console.warn(`No WebSocket found for clientId ${clientId}`);
|
|
1049
|
-
this.wsClients.delete(clientId);
|
|
1050
|
-
}
|
|
923
|
+
this.webSocketsManager = new WebSocketsManager(this.wsClients, this.redisClient, server);
|
|
924
|
+
await this.webSocketsManager.listen();
|
|
1051
925
|
}
|
|
1052
926
|
setupHttpsServer() {
|
|
1053
927
|
let server;
|
package/models/image.cjs
CHANGED
|
@@ -291,7 +291,7 @@ module.exports = (sequelize, DataTypes) => {
|
|
|
291
291
|
if (removed) {
|
|
292
292
|
image.deleted = true;
|
|
293
293
|
await image.save();
|
|
294
|
-
import("../active-citizen/llms/collectionImageGenerator.js").then(async ({ CollectionImageGenerator }) => {
|
|
294
|
+
import("../active-citizen/llms/imageGeneration/collectionImageGenerator.js").then(async ({ CollectionImageGenerator }) => {
|
|
295
295
|
try {
|
|
296
296
|
const mediaManager = new CollectionImageGenerator();
|
|
297
297
|
await mediaManager.deleteMediaFormatsUrls(image.formats ? JSON.parse(image.formats) : []);
|
package/models/index.cjs
CHANGED
|
@@ -48,18 +48,26 @@ if (process.env.NODE_ENV === "production") {
|
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
else {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
51
|
+
let config;
|
|
52
|
+
try {
|
|
53
|
+
sequelize = new Sequelize(process.env.YP_DEV_DATABASE_NAME, process.env.YP_DEV_DATABASE_USERNAME, process.env.YP_DEV_DATABASE_PASSWORD, {
|
|
54
|
+
dialect: "postgres",
|
|
55
|
+
protocol: "postgres",
|
|
56
|
+
host: process.env.YP_DEV_DATABASE_HOST,
|
|
57
|
+
port: process.env.YP_DEV_DATABASE_PORT,
|
|
58
|
+
minifyAliases: true,
|
|
59
|
+
dialectOptions: {
|
|
60
|
+
ssl: false,
|
|
61
|
+
rejectUnauthorized: false,
|
|
62
|
+
},
|
|
63
|
+
logging: false,
|
|
64
|
+
operatorsAliases: operatorsAliases,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
console.error("Error reading or parsing config file:", error);
|
|
69
|
+
process.exit(1);
|
|
70
|
+
}
|
|
63
71
|
}
|
|
64
72
|
const db = {};
|
|
65
73
|
async function createCompoundIndexes(indexCommands) {
|
package/models/video.cjs
CHANGED
|
@@ -821,7 +821,7 @@ module.exports = (sequelize, DataTypes) => {
|
|
|
821
821
|
if (removed) {
|
|
822
822
|
video.deleted = true;
|
|
823
823
|
await video.save();
|
|
824
|
-
import("../active-citizen/llms/collectionImageGenerator.js").then(async ({ CollectionImageGenerator }) => {
|
|
824
|
+
import("../active-citizen/llms/imageGeneration/collectionImageGenerator.js").then(async ({ CollectionImageGenerator }) => {
|
|
825
825
|
try {
|
|
826
826
|
const mediaManager = new CollectionImageGenerator();
|
|
827
827
|
let formats = video.formats;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yrpri/api",
|
|
3
|
-
"version": "9.0.
|
|
3
|
+
"version": "9.0.92",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Robert Bjarnason & Citizens Foundation",
|
|
6
6
|
"repository": {
|
|
@@ -18,50 +18,51 @@
|
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@airbrake/node": "^2.1.4",
|
|
20
20
|
"@aws-sdk/client-s3": "^3.617.0",
|
|
21
|
-
"@
|
|
21
|
+
"@google-cloud/aiplatform": "^3.34.0",
|
|
22
22
|
"@google-cloud/speech": "^6.7.0",
|
|
23
|
-
"@google-cloud/storage": "^7.
|
|
24
|
-
"@google-cloud/translate": "^8.0
|
|
23
|
+
"@google-cloud/storage": "^7.15.0",
|
|
24
|
+
"@google-cloud/translate": "^8.5.0",
|
|
25
|
+
"@google-cloud/vertexai": "^1.9.3",
|
|
25
26
|
"@google-cloud/vision": "^4.0.3",
|
|
26
|
-
"@policysynth/agents": "^1.3.
|
|
27
|
-
"async": "^3.2.
|
|
27
|
+
"@policysynth/agents": "^1.3.64",
|
|
28
|
+
"async": "^3.2.6",
|
|
28
29
|
"authorized": "^1.0.0",
|
|
29
|
-
"aws-sdk": "^2.
|
|
30
|
-
"axios": "^1.
|
|
30
|
+
"aws-sdk": "^2.1692.0",
|
|
31
|
+
"axios": "^1.7.9",
|
|
31
32
|
"bcrypt": "^5.1.0",
|
|
32
|
-
"body-parser": "^1.20.
|
|
33
|
-
"bull": "^4.
|
|
33
|
+
"body-parser": "^1.20.3",
|
|
34
|
+
"bull": "^4.16.5",
|
|
34
35
|
"bunyan": "^1.8.12",
|
|
35
36
|
"bunyan-prettystream": "git+https://github.com/rbjarnason/node-bunyan-prettystream.git",
|
|
36
|
-
"cheerio": "^1.0.0
|
|
37
|
+
"cheerio": "^1.0.0",
|
|
37
38
|
"color-hash": "^2.0.1",
|
|
38
39
|
"colors": "^1.4.0",
|
|
39
|
-
"compression": "^1.
|
|
40
|
+
"compression": "^1.8.0",
|
|
40
41
|
"concat-stream": "^2.0.0",
|
|
41
42
|
"connect-redis": "^7.1.0",
|
|
42
|
-
"cookie-parser": "^1.4.
|
|
43
|
+
"cookie-parser": "^1.4.7",
|
|
43
44
|
"cors": "^2.8.5",
|
|
44
45
|
"deep-equal": "^2.1.0",
|
|
45
46
|
"docx": "^8.5.0",
|
|
46
47
|
"download-file": "^0.1.5",
|
|
47
48
|
"ejs": "^3.1.8",
|
|
48
49
|
"exceljs": "^4.2.0",
|
|
49
|
-
"express": "^4.
|
|
50
|
+
"express": "^4.21.2",
|
|
50
51
|
"express-rate-limit": "^7.4.0",
|
|
51
52
|
"express-session": "git+https://github.com/rbjarnason/session.git#upgrade-21",
|
|
52
53
|
"express-useragent": "^1.0.13",
|
|
53
54
|
"farmhash": "3.3.1",
|
|
54
55
|
"html-to-docx": "^1.8.0",
|
|
55
|
-
"i18next": "^
|
|
56
|
+
"i18next": "^24.2.2",
|
|
56
57
|
"i18next-node-fs-backend": "^2.1.3",
|
|
57
58
|
"image-size": "^1.0.2",
|
|
58
59
|
"ip": "^2.0.1",
|
|
59
|
-
"isbot": "^5.1.
|
|
60
|
+
"isbot": "^5.1.22",
|
|
60
61
|
"iso-639-1": "^3.1.0",
|
|
61
|
-
"jsonrepair": "^3.
|
|
62
|
+
"jsonrepair": "^3.12.0",
|
|
62
63
|
"knuth-shuffle-seeded": "^1.0.6",
|
|
63
64
|
"lodash": "^4.17.15",
|
|
64
|
-
"marked": "^15.0.
|
|
65
|
+
"marked": "^15.0.7",
|
|
65
66
|
"moment": "^2.24.0",
|
|
66
67
|
"morgan": "~1.10.0",
|
|
67
68
|
"multer": "1.4.5-lts.1",
|
|
@@ -71,7 +72,7 @@
|
|
|
71
72
|
"nodemailer": "^6.9.9",
|
|
72
73
|
"nodemailer-sendgrid": "^1.0.3",
|
|
73
74
|
"open-graph-scraper": "^6.7.0",
|
|
74
|
-
"openai": "^4.
|
|
75
|
+
"openai": "^4.85.1",
|
|
75
76
|
"passport": "^0.6.0",
|
|
76
77
|
"passport-facebook": "^3.0.0",
|
|
77
78
|
"passport-github": "^1.0.0",
|
|
@@ -80,14 +81,14 @@
|
|
|
80
81
|
"passport-openidconnect": "git+https://github.com/rbjarnason/passport-openidconnect.git",
|
|
81
82
|
"passport-saml": "git+https://github.com/rbjarnason/passport-saml.git#smarternj",
|
|
82
83
|
"passport-sso": "git+https://github.com/rbjarnason/passport-sso.git",
|
|
83
|
-
"pg": "^8.
|
|
84
|
+
"pg": "^8.13.3",
|
|
84
85
|
"pg-hstore": "^2.3.4",
|
|
85
86
|
"pgvector": "^0.2.0",
|
|
86
87
|
"ps": "^1.0.0",
|
|
87
88
|
"pug": "^3.0.2",
|
|
88
89
|
"randomstring": "^1.2.3",
|
|
89
90
|
"rate-limit-redis": "^4.2.0",
|
|
90
|
-
"redis": "^4.
|
|
91
|
+
"redis": "^4.7.0",
|
|
91
92
|
"replicate": "^0.32.0",
|
|
92
93
|
"request": "^2.88.2",
|
|
93
94
|
"request-ip": "^3.3.0",
|
|
@@ -96,8 +97,8 @@
|
|
|
96
97
|
"sequelize-cli": "^6.2.0",
|
|
97
98
|
"sharp": "^0.33.5",
|
|
98
99
|
"sitemap": "^7.1.2",
|
|
99
|
-
"socket.io": "^4.
|
|
100
|
-
"stripe": "^17.
|
|
100
|
+
"socket.io": "^4.8.1",
|
|
101
|
+
"stripe": "^17.6.0",
|
|
101
102
|
"striptags": "^3.2.0",
|
|
102
103
|
"uuid": "^10.0.0",
|
|
103
104
|
"weaviate-ts-client": "^2.0.0",
|
|
@@ -116,15 +117,15 @@
|
|
|
116
117
|
"@types/html-docx-js": "^0.3.4",
|
|
117
118
|
"@types/marked": "^6.0.0",
|
|
118
119
|
"@types/morgan": "^1.9.9",
|
|
119
|
-
"@types/node": "^
|
|
120
|
+
"@types/node": "^22.13.4",
|
|
120
121
|
"@types/passport": "^1.0.16",
|
|
121
|
-
"@types/pg": "^8.
|
|
122
|
+
"@types/pg": "^8.11.11",
|
|
122
123
|
"@types/request-ip": "^0.0.41",
|
|
123
124
|
"@types/sequelize": "^4.28.9",
|
|
124
125
|
"@types/sharp": "^0.32.0",
|
|
125
126
|
"@types/uuid": "^10.0.0",
|
|
126
127
|
"@types/validator": "^13.11.9",
|
|
127
|
-
"@types/ws": "^8.5.
|
|
128
|
+
"@types/ws": "^8.5.14",
|
|
128
129
|
"axios": "^1.4.0",
|
|
129
130
|
"colors": "^1.4.0",
|
|
130
131
|
"csv-parse": "^5.3.1",
|
|
@@ -163,6 +164,6 @@
|
|
|
163
164
|
"node_modules"
|
|
164
165
|
],
|
|
165
166
|
"engines": {
|
|
166
|
-
"node": "
|
|
167
|
+
"node": "22.14.0"
|
|
167
168
|
}
|
|
168
169
|
}
|
|
@@ -12,12 +12,18 @@ const wildCardDomainNames = [
|
|
|
12
12
|
"betrireykjavik.is",
|
|
13
13
|
"betraisland.is",
|
|
14
14
|
"yrpri.org",
|
|
15
|
+
"evoly.ai",
|
|
15
16
|
"tarsalgo.net",
|
|
16
17
|
"ypus.org",
|
|
17
18
|
"idea-synergy.com",
|
|
18
19
|
"localhost:4242",
|
|
19
20
|
];
|
|
20
21
|
var generateSitemap = async function (req, res) {
|
|
22
|
+
if (!req.ypDomain) {
|
|
23
|
+
log.error("No domain found in sitemap generation");
|
|
24
|
+
res.status(500);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
21
27
|
const domainId = req.ypDomain.id;
|
|
22
28
|
const domainName = req.ypDomain.domain_name;
|
|
23
29
|
let community = req.ypCommunity && req.ypCommunity.id ? req.ypCommunity : null;
|