Skip to content

Commit bff9494

Browse files
committed
Update dependencies and fix TypeScript strict mode errors
1 parent 0042131 commit bff9494

File tree

11 files changed

+434
-247
lines changed

11 files changed

+434
-247
lines changed

app/ui/src/hooks/useMessage.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ export const useMessage = () => {
170170
setHistory(responseData.history);
171171
setMessages(newMessage);
172172
setIsProcessing(false);
173-
reader.releaseLock();
174173
break;
175174
}
176175
}

server/package.json

+9-8
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"@fastify/autoload": "^5.0.0",
3030
"@fastify/cookie": "^9.1.0",
3131
"@fastify/cors": "^8.3.0",
32-
"@fastify/jwt": "^7.0.0",
32+
"@fastify/jwt": "^8.0.0",
3333
"@fastify/multipart": "^7.6.0",
3434
"@fastify/sensible": "^5.0.0",
3535
"@fastify/session": "^10.5.0",
@@ -62,10 +62,10 @@
6262
"copyfiles": "^2.4.1",
6363
"d3-dsv": "2",
6464
"discord.js": "^14.11.0",
65-
"fastify": "^4.0.0",
66-
"fastify-cli": "^5.7.1",
67-
"fastify-plugin": "^4.0.0",
68-
"fastify-raw-body": "4.0.0",
65+
"fastify": "^4.26.2",
66+
"fastify-cli": "6.1.1",
67+
"fastify-plugin": "4.0.0",
68+
"fastify-raw-body": "^4.3.0",
6969
"fastify-sse-v2": "^3.1.1",
7070
"google-auth-library": "^8.8.0",
7171
"grammy": "^1.16.2",
@@ -87,13 +87,14 @@
8787
},
8888
"devDependencies": {
8989
"@types/bcryptjs": "^2.4.2",
90-
"@types/node": "^18.0.0",
90+
"@types/node": "20.4.4",
9191
"@types/pubsub-js": "^1.8.3",
9292
"@types/tap": "^15.0.5",
93-
"fastify-tsconfig": "^1.0.1",
93+
"c8": "9.0.0",
94+
"fastify-tsconfig": "2.0.0",
9495
"prisma": "^5.9.1",
9596
"tap": "^16.1.0",
96-
"typescript": "^4.5.4"
97+
"typescript": "5.2.2"
9798
},
9899
"resolutions": {
99100
"@langchain/core": "0.1.43"

server/src/handlers/api/v1/bot/playground/chat.handler.ts

-1
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,6 @@ export const chatRequestStreamHandler = async (
510510
}),
511511
},
512512
});
513-
514513
reply.sse({
515514
event: "result",
516515
id: "",

server/src/handlers/api/v1/yt/get.handler.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { FastifyRequest, FastifyReply } from "fastify";
22
import { GetYoutubeTranscript } from "./types";
3-
import { YtTranscript } from "yt-transcript"
43

54
const getYoutubeTranscript = async (url: string) => {
5+
const { YtTranscript } = await import("yt-transcript");
66
const transcript = new YtTranscript({ url });
77
const data = await transcript.listAllTranscripts();
88
return data;
+40-43
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,48 @@
11
import { BaseDocumentLoader } from "langchain/document_loaders/base";
22
import { Document } from "langchain/document";
3-
import { YtTranscript } from "yt-transcript";
43

54
export interface YoutubeTranscriptParams {
6-
url: string;
7-
language_code: string;
5+
url: string;
6+
language_code: string;
87
}
98

109
export class DialoqbaseYoutubeTranscript
11-
extends BaseDocumentLoader
12-
implements YoutubeTranscriptParams {
13-
language_code: string;
14-
url: string;
15-
16-
constructor({ language_code, url }: YoutubeTranscriptParams) {
17-
super();
18-
this.language_code = language_code;
19-
this.url = url
20-
}
21-
22-
23-
24-
async load(): Promise<Document<Record<string, any>>[]> {
25-
const ytTranscript = new YtTranscript({
26-
url: this.url,
27-
})
28-
29-
const script = await ytTranscript.getTranscript(this.language_code)
30-
31-
if (!script) throw new Error("No script found")
32-
33-
34-
let text = ""
35-
36-
script.forEach((item) => {
37-
text += item.text + " "
38-
})
39-
40-
41-
return [
42-
{
43-
metadata: {
44-
source: this.url,
45-
audio: { chunks: script }
46-
},
47-
pageContent: text
48-
}
49-
]
50-
}
10+
extends BaseDocumentLoader
11+
implements YoutubeTranscriptParams
12+
{
13+
language_code: string;
14+
url: string;
15+
16+
constructor({ language_code, url }: YoutubeTranscriptParams) {
17+
super();
18+
this.language_code = language_code;
19+
this.url = url;
20+
}
21+
22+
async load(): Promise<Document<Record<string, any>>[]> {
23+
const { YtTranscript } = await import("yt-transcript");
24+
25+
const ytTranscript = new YtTranscript({
26+
url: this.url,
27+
});
28+
29+
const script = await ytTranscript.getTranscript(this.language_code);
30+
31+
if (!script) throw new Error("No script found");
32+
33+
let text = "";
34+
35+
script.forEach((item) => {
36+
text += item.text + " ";
37+
});
38+
39+
return [
40+
{
41+
metadata: {
42+
source: this.url,
43+
},
44+
pageContent: text,
45+
},
46+
];
47+
}
5148
}

server/src/plugins/bull.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import fp from "fastify-plugin";
22
import { FastifyPluginAsync } from "fastify";
33

4-
import * as Queue from "bull";
4+
import Queue from "bull";
55
import { join } from "path";
66

77
declare module "fastify" {

server/src/plugins/jwt.ts

+46-47
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ declare module "@fastify/jwt" {
1111
}
1212
}
1313

14-
1514
export default fp<FastifyJWTOptions>(async (fastify, opts) => {
1615
fastify.register(fastifyJwt, {
1716
secret: process.env.DB_SECRET_KEY!,
@@ -20,60 +19,60 @@ export default fp<FastifyJWTOptions>(async (fastify, opts) => {
2019
},
2120
});
2221

23-
fastify.decorate(
24-
"authenticate",
25-
async function (request: FastifyRequest, reply: FastifyReply) {
26-
try {
27-
const token = request.headers.authorization;
28-
if (token && token.startsWith("db_")) {
29-
const apiKey = await fastify.prisma.userApiKey.findFirst({
30-
where: {
31-
api_key: token,
32-
},
33-
include: {
34-
User: true,
35-
}
36-
});
37-
38-
if (!apiKey) {
39-
return reply.status(401).send({
40-
message: "Unauthorized",
41-
});
42-
}
43-
request.user = {
44-
user_id: apiKey.User.user_id,
45-
username: apiKey.User.username,
46-
is_admin: apiKey.User.isAdministrator,
47-
};
48-
} else {
49-
50-
await request.jwtVerify();
51-
const { user_id } = request.user;
22+
async function authenticate(request: FastifyRequest, reply: FastifyReply) {
23+
try {
24+
const token = request.headers.authorization;
25+
if (token && token.startsWith("db_")) {
26+
const apiKey = await fastify.prisma.userApiKey.findFirst({
27+
where: {
28+
api_key: token,
29+
},
30+
include: {
31+
User: true,
32+
},
33+
});
5234

53-
const user = await fastify.prisma.user.findUnique({
54-
where: {
55-
user_id,
56-
},
35+
if (!apiKey) {
36+
return reply.status(401).send({
37+
message: "Unauthorized",
5738
});
39+
}
40+
request.user = {
41+
user_id: apiKey.User.user_id,
42+
username: apiKey.User.username,
43+
is_admin: apiKey.User.isAdministrator,
44+
};
45+
} else {
46+
await request.jwtVerify();
47+
const { user_id } = request.user;
48+
49+
const user = await fastify.prisma.user.findUnique({
50+
where: {
51+
user_id,
52+
},
53+
});
5854

59-
if (!user) {
60-
throw new Error("User not found");
61-
}
62-
request.user = {
63-
user_id: user.user_id,
64-
username: user.username,
65-
is_admin: user.isAdministrator,
66-
};
55+
if (!user) {
56+
throw new Error("User not found");
6757
}
68-
} catch (err) {
69-
reply.send(err);
58+
request.user = {
59+
user_id: user.user_id,
60+
username: user.username,
61+
is_admin: user.isAdministrator,
62+
};
7063
}
71-
},
72-
);
64+
} catch (err) {
65+
reply.send(err);
66+
}
67+
}
68+
fastify.decorate("authenticate", authenticate);
7369
});
7470

7571
declare module "fastify" {
7672
export interface FastifyInstance {
77-
authenticate(): Promise<void>;
73+
authenticate(
74+
request: FastifyRequest,
75+
reply: FastifyReply
76+
): Promise<undefined>;
7877
}
7978
}

server/src/utils/store.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ interface SearchEmbeddingsResponse {
1818
export class DialoqbaseVectorStore extends VectorStore {
1919
botId: string;
2020
sourceId: string | null;
21-
embeddings: Embeddings;
21+
declare embeddings: Embeddings;
2222

2323
constructor(embeddings: Embeddings, args: DialoqbaseLibArgs) {
2424
super(embeddings, args);

server/src/utils/youtube.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as ytdl from "ytdl-core";
1+
import ytdl from "ytdl-core";
22

33
export function isYouTubeUrl(url: string): boolean {
44
const youtubeRegex = /^(https?:\/\/)?(www\.)?(youtube\.com|youtu\.be)\/.+$/;

server/tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"sourceMap": true,
66
"allowSyntheticDefaultImports": true,
77
"checkJs": false,
8+
"strict": false
89
},
910
"include": ["src/**/*.ts"],
1011
"exclude": [

0 commit comments

Comments
 (0)