kyd-shared-badge 0.3.1 → 0.3.2
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/package.json +1 -1
- package/src/lib/routes.ts +11 -16
package/package.json
CHANGED
package/src/lib/routes.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { NextRequest } from 'next/server';
|
|
|
5
5
|
import { streamText } from 'ai';
|
|
6
6
|
import { bedrock } from '@ai-sdk/amazon-bedrock';
|
|
7
7
|
|
|
8
|
-
import { verifyCognito } from './auth-verify';
|
|
8
|
+
// import { verifyCognito } from './auth-verify';
|
|
9
9
|
import { getHistory, putMessage } from './chat-store';
|
|
10
10
|
import { aggregateUserData, cleanDeveloperProfile, buildAllContextPrompt, getReportGraphData } from './context';
|
|
11
11
|
import { checkAndConsumeToken } from './rate-limit';
|
|
@@ -15,22 +15,23 @@ import { createSession } from './chat-store';
|
|
|
15
15
|
|
|
16
16
|
export const runtime = 'nodejs';
|
|
17
17
|
|
|
18
|
-
export async function chatStreamRoute(req: NextRequest) {
|
|
18
|
+
export async function chatStreamRoute(req: NextRequest, userId: string, companyId?: string) {
|
|
19
19
|
try {
|
|
20
|
-
const user = await verifyCognito(req);
|
|
20
|
+
// const user = await verifyCognito(req);
|
|
21
|
+
|
|
21
22
|
const { sessionId, content, badgeId } = await req.json();
|
|
22
23
|
if (!content || !sessionId) {
|
|
23
24
|
return Response.json({ error: 'Missing sessionId or content' }, { status: 400 });
|
|
24
25
|
}
|
|
25
26
|
|
|
26
|
-
const allowed = await checkAndConsumeToken(
|
|
27
|
+
const allowed = await checkAndConsumeToken(userId, 20);
|
|
27
28
|
if (!allowed) {
|
|
28
29
|
return Response.json({ error: 'Rate limit exceeded' }, { status: 429 });
|
|
29
30
|
}
|
|
30
31
|
|
|
31
32
|
await putMessage({ sessionId, role: 'user', content });
|
|
32
33
|
|
|
33
|
-
const aggregated = await aggregateUserData(
|
|
34
|
+
const aggregated = await aggregateUserData(userId, !!companyId, companyId);
|
|
34
35
|
const cleaned = cleanDeveloperProfile(aggregated);
|
|
35
36
|
const graphData = await getReportGraphData(badgeId);
|
|
36
37
|
const system = buildAllContextPrompt(cleaned, graphData, { concise: true });
|
|
@@ -68,17 +69,13 @@ function tryParseEvidenceServer(text: string): any | null {
|
|
|
68
69
|
return null;
|
|
69
70
|
}
|
|
70
71
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
export async function createSessionRoute(req: NextRequest) {
|
|
72
|
+
export async function POST(req: NextRequest, userId: string, companyId?: string) {
|
|
76
73
|
try {
|
|
77
|
-
const user = await verifyCognito(req);
|
|
74
|
+
// const user = await verifyCognito(req);
|
|
78
75
|
const body = await req.json().catch(() => ({}));
|
|
79
76
|
const sessionId = await createSession({
|
|
80
|
-
userId:
|
|
81
|
-
companyId:
|
|
77
|
+
userId: userId,
|
|
78
|
+
companyId: companyId,
|
|
82
79
|
model: body?.model,
|
|
83
80
|
promptId: body?.promptId,
|
|
84
81
|
promptVersion: body?.promptVersion,
|
|
@@ -89,6 +86,4 @@ export async function createSessionRoute(req: NextRequest) {
|
|
|
89
86
|
if (e instanceof Response) return e;
|
|
90
87
|
return Response.json({ error: 'Failed to create session' }, { status: 500 });
|
|
91
88
|
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
|
|
89
|
+
}
|