Skip to content

Commit 6e7c042

Browse files
Sessions unify with properties (#5101)
* unify the sessions hassessions query with properties * gent ypes * Fix TypeScript build error in sessions page - Remove hasSessions.isLoading reference since hasSessions is now a boolean - Include properties.isLoading in useSessions hook loading state - Ensures proper loading state for session detection functionality 🤖 Generated with [Claude Code](https://claude.ai/code) Co-authored-by: Justin Torre <chitalian@users.noreply.github.com> --------- Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com> Co-authored-by: Justin Torre <chitalian@users.noreply.github.com>
1 parent 6726313 commit 6e7c042

File tree

8 files changed

+17
-158
lines changed

8 files changed

+17
-158
lines changed

bifrost/lib/clients/jawnTypes/public.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -398,9 +398,6 @@ export interface paths {
398398
"/v1/test/gateway-request": {
399399
post: operations["SendTestRequest"];
400400
};
401-
"/v1/session/has-session": {
402-
get: operations["HasSession"];
403-
};
404401
"/v1/session/query": {
405402
post: operations["GetSessions"];
406403
};
@@ -6533,16 +6530,6 @@ export interface operations {
65336530
};
65346531
};
65356532
};
6536-
HasSession: {
6537-
responses: {
6538-
/** @description Ok */
6539-
200: {
6540-
content: {
6541-
"application/json": components["schemas"]["Result_boolean.string_"];
6542-
};
6543-
};
6544-
};
6545-
};
65466533
GetSessions: {
65476534
requestBody: {
65486535
content: {

docs/swagger.json

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18842,32 +18842,6 @@
1884218842
}
1884318843
}
1884418844
},
18845-
"/v1/session/has-session": {
18846-
"get": {
18847-
"operationId": "HasSession",
18848-
"responses": {
18849-
"200": {
18850-
"description": "Ok",
18851-
"content": {
18852-
"application/json": {
18853-
"schema": {
18854-
"$ref": "#/components/schemas/Result_boolean.string_"
18855-
}
18856-
}
18857-
}
18858-
}
18859-
},
18860-
"tags": [
18861-
"Session"
18862-
],
18863-
"security": [
18864-
{
18865-
"api_key": []
18866-
}
18867-
],
18868-
"parameters": []
18869-
}
18870-
},
1887118845
"/v1/session/query": {
1887218846
"post": {
1887318847
"operationId": "GetSessions",

valhalla/jawn/src/controllers/public/sessionController.ts

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -71,45 +71,6 @@ const kvCache = new KVCache(60 * 1000); // 5 minutes
7171
@Tags("Session")
7272
@Security("api_key")
7373
export class SessionController extends Controller {
74-
@Get("/has-session")
75-
public async hasSession(
76-
@Request() request: JawnAuthenticatedRequest
77-
): Promise<Result<boolean, string>> {
78-
const found = await cacheResultCustom<boolean, string>(
79-
`has-session-${request.authParams.organizationId}`,
80-
async () => {
81-
const sessionManager = new SessionManager(request.authParams);
82-
const result = await sessionManager.getSessionsCount({
83-
filter: {},
84-
search: "",
85-
timeFilter: {
86-
startTimeUnixMs: new Date().getTime() - 1000 * 60 * 60 * 30,
87-
endTimeUnixMs: new Date().getTime(),
88-
},
89-
timezoneDifference: 0,
90-
});
91-
if (result.error || !result.data) {
92-
return err("Error finding sessions");
93-
} else {
94-
if (result.data?.count > 0) {
95-
return ok(true);
96-
} else {
97-
return err("No sessions found");
98-
}
99-
}
100-
},
101-
kvCache
102-
);
103-
if (found.error) {
104-
console.error("Error finding sessions", found.error);
105-
this.setStatus(500);
106-
} else {
107-
this.setStatus(200);
108-
}
109-
110-
return found;
111-
}
112-
11374
@Post("query")
11475
public async getSessions(
11576
@Body()

valhalla/jawn/src/tsoa-build/public/routes.ts

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8662,37 +8662,6 @@ export function RegisterRoutes(app: Router) {
86628662
}
86638663
});
86648664
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
8665-
const argsSessionController_hasSession: Record<string, TsoaRoute.ParameterSchema> = {
8666-
request: {"in":"request","name":"request","required":true,"dataType":"object"},
8667-
};
8668-
app.get('/v1/session/has-session',
8669-
authenticateMiddleware([{"api_key":[]}]),
8670-
...(fetchMiddlewares<RequestHandler>(SessionController)),
8671-
...(fetchMiddlewares<RequestHandler>(SessionController.prototype.hasSession)),
8672-
8673-
async function SessionController_hasSession(request: ExRequest, response: ExResponse, next: any) {
8674-
8675-
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
8676-
8677-
let validatedArgs: any[] = [];
8678-
try {
8679-
validatedArgs = templateService.getValidatedArgs({ args: argsSessionController_hasSession, request, response });
8680-
8681-
const controller = new SessionController();
8682-
8683-
await templateService.apiHandler({
8684-
methodName: 'hasSession',
8685-
controller,
8686-
response,
8687-
next,
8688-
validatedArgs,
8689-
successStatus: undefined,
8690-
});
8691-
} catch (err) {
8692-
return next(err);
8693-
}
8694-
});
8695-
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
86968665
const argsSessionController_getSessions: Record<string, TsoaRoute.ParameterSchema> = {
86978666
requestBody: {"in":"body","name":"requestBody","required":true,"ref":"SessionQueryParams"},
86988667
request: {"in":"request","name":"request","required":true,"dataType":"object"},

valhalla/jawn/src/tsoa-build/public/swagger.json

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18842,32 +18842,6 @@
1884218842
}
1884318843
}
1884418844
},
18845-
"/v1/session/has-session": {
18846-
"get": {
18847-
"operationId": "HasSession",
18848-
"responses": {
18849-
"200": {
18850-
"description": "Ok",
18851-
"content": {
18852-
"application/json": {
18853-
"schema": {
18854-
"$ref": "#/components/schemas/Result_boolean.string_"
18855-
}
18856-
}
18857-
}
18858-
}
18859-
},
18860-
"tags": [
18861-
"Session"
18862-
],
18863-
"security": [
18864-
{
18865-
"api_key": []
18866-
}
18867-
],
18868-
"parameters": []
18869-
}
18870-
},
1887118845
"/v1/session/query": {
1887218846
"post": {
1887318847
"operationId": "GetSessions",

web/components/templates/sessions/sessionsPage.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ const SessionsPage = (props: SessionsPageProps) => {
207207
);
208208

209209
const isSessionsLoading =
210-
isLoading || allNames.isLoading || names.isLoading || hasSessions.isLoading;
210+
isLoading || allNames.isLoading || names.isLoading;
211211

212212
// Helper function to get TimeFilter object
213213
const getTimeFilterObject = (start: Date, end: Date): TimeFilter => ({
@@ -297,7 +297,7 @@ const SessionsPage = (props: SessionsPageProps) => {
297297
}
298298
}, [router.query.page]);
299299

300-
return hasSessions.data?.data?.data || isSessionsLoading ? (
300+
return hasSessions || isSessionsLoading ? (
301301
<main className="flex h-screen w-full animate-fade-in flex-col">
302302
<Tabs
303303
value={currentTab}

web/lib/clients/jawnTypes/public.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -398,9 +398,6 @@ export interface paths {
398398
"/v1/test/gateway-request": {
399399
post: operations["SendTestRequest"];
400400
};
401-
"/v1/session/has-session": {
402-
get: operations["HasSession"];
403-
};
404401
"/v1/session/query": {
405402
post: operations["GetSessions"];
406403
};
@@ -6533,16 +6530,6 @@ export interface operations {
65336530
};
65346531
};
65356532
};
6536-
HasSession: {
6537-
responses: {
6538-
/** @description Ok */
6539-
200: {
6540-
content: {
6541-
"application/json": components["schemas"]["Result_boolean.string_"];
6542-
};
6543-
};
6544-
};
6545-
};
65466533
GetSessions: {
65476534
requestBody: {
65486535
content: {

web/services/hooks/sessions.tsx

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,26 @@ const useSessions = ({
6767
refetchIntervalInBackground: false,
6868
refetchInterval: false,
6969
});
70+
const properties = useQuery({
71+
queryKey: ["/v1/property/query", org?.currentOrg?.id],
72+
queryFn: async (query) => {
73+
const jawn = getJawnClient(query.queryKey[1]);
74+
const res = await jawn.POST("/v1/property/query", {
75+
body: {},
76+
});
77+
return res.data;
78+
},
79+
refetchOnWindowFocus: false,
80+
});
7081

7182
return {
7283
sessions: data?.data?.data || [],
7384
refetch,
74-
isLoading,
85+
isLoading: isLoading || properties.isLoading,
7586
isRefetching,
76-
hasSessions: useQuery({
77-
queryKey: ["has-sessions", org?.currentOrg?.id],
78-
queryFn: async () => {
79-
const jawnClient = getJawnClient(org?.currentOrg?.id);
80-
return await jawnClient.GET("/v1/session/has-session");
81-
},
82-
}),
87+
hasSessions: !!properties.data?.data?.find((p) =>
88+
p.property.toLowerCase().includes("helicone-session"),
89+
),
8390
};
8491
};
8592

0 commit comments

Comments
 (0)