kyd-shared-badge 0.3.14 → 0.3.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/package.json +1 -1
- package/src/lib/context.ts +5 -0
- package/src/lib/routes.ts +9 -2
package/package.json
CHANGED
package/src/lib/context.ts
CHANGED
|
@@ -150,4 +150,9 @@ async function getJsonFromS3(bucket: string, key: string): Promise<any> {
|
|
|
150
150
|
export async function getReportGraphData(badgeId: string): Promise<GraphInsightsPayload | undefined> {
|
|
151
151
|
const badge = await doc.send(new GetCommand({ TableName: badgeTableName, Key: { badgeId } }));
|
|
152
152
|
return badge.Item?.assessmentResult?.graph_insights as GraphInsightsPayload | undefined;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export async function getBadgeUserId(badgeId: string): Promise<string> {
|
|
156
|
+
const badge = await doc.send(new GetCommand({ TableName: badgeTableName, Key: { badgeId } }));
|
|
157
|
+
return badge.Item?.userId as string;
|
|
153
158
|
}
|
package/src/lib/routes.ts
CHANGED
|
@@ -6,7 +6,13 @@ import { streamText } from 'ai';
|
|
|
6
6
|
import { bedrock } from '@ai-sdk/amazon-bedrock';
|
|
7
7
|
|
|
8
8
|
import { getHistory, putMessage } from './chat-store';
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
aggregateUserData,
|
|
11
|
+
cleanDeveloperProfile,
|
|
12
|
+
buildAllContextPrompt,
|
|
13
|
+
getReportGraphData,
|
|
14
|
+
getBadgeUserId
|
|
15
|
+
} from './context';
|
|
10
16
|
import { checkAndConsumeToken } from './rate-limit';
|
|
11
17
|
|
|
12
18
|
import { createSession } from './chat-store';
|
|
@@ -29,7 +35,8 @@ export async function chatStreamRoute(req: NextRequest, userId: string, companyI
|
|
|
29
35
|
|
|
30
36
|
await putMessage({ sessionId, role: 'user', content });
|
|
31
37
|
|
|
32
|
-
const
|
|
38
|
+
const badgeUserId = await getBadgeUserId(badgeId);
|
|
39
|
+
const aggregated = await aggregateUserData(badgeUserId, !!companyId, companyId);
|
|
33
40
|
const cleaned = cleanDeveloperProfile(aggregated);
|
|
34
41
|
const graphData = await getReportGraphData(badgeId);
|
|
35
42
|
const system = buildAllContextPrompt(cleaned, graphData, { concise: true });
|