Skip to content

Commit 97e1f22

Browse files
committed
modify search api scope
Signed-off-by: Arnesh Dadhich <arneshdadhich0011@gmail.com>
1 parent c581904 commit 97e1f22

6 files changed

Lines changed: 45 additions & 27 deletions

File tree

src/client/acontext-py/src/acontext/resources/async_sessions.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -508,25 +508,25 @@ async def search(
508508
self,
509509
*,
510510
query: str,
511-
user_id: str,
511+
user: str,
512512
limit: int | None = None,
513513
) -> SessionSearchResult:
514514
"""Search for sessions by semantic similarity to a query string.
515515
516516
Args:
517517
query: The search query text.
518-
user_id: The User ID to search within.
518+
user: User identifier to scope the search (e.g., email address).
519519
limit: Maximum number of results to return (1-100, default 10).
520520
521521
Returns:
522522
SessionSearchResult containing list of matching session UUIDs.
523523
524524
Example:
525-
>>> result = await client.sessions.search(query="conversations", user_id="user_123")
525+
>>> result = await client.sessions.search(query="conversations", user="alice@acontext.io")
526526
>>> for session_id in result.session_ids:
527527
... print(session_id)
528528
"""
529-
params = build_params(query=query, user_id=user_id, limit=limit)
529+
params = build_params(query=query, user=user, limit=limit)
530530
data = await self._requester.request(
531531
"GET", "/sessions/search", params=params or None
532532
)

src/client/acontext-py/src/acontext/resources/sessions.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -502,16 +502,14 @@ def search(
502502
self,
503503
*,
504504
query: str,
505-
user_id: str,
506-
project_id: str,
505+
user: str,
507506
limit: int | None = None,
508507
) -> SessionSearchResult:
509508
"""Search for sessions by semantic similarity to a query string.
510509
511510
Args:
512511
query: The search query text.
513-
user_id: The User ID to search within.
514-
project_id: The Project ID to search within.
512+
user: User identifier to scope the search (e.g., email address).
515513
limit: Maximum number of results to return (1-100, default 10).
516514
517515
Returns:
@@ -520,12 +518,11 @@ def search(
520518
Example:
521519
>>> result = client.sessions.search(
522520
... query="conversations about authentication",
523-
... user_id="user_123",
524-
... project_id="proj_456"
521+
... user="alice@acontext.io"
525522
... )
526523
>>> for session_id in result.session_ids:
527524
... print(session_id)
528525
"""
529-
params = build_params(query=query, user_id=user_id, project_id=project_id, limit=limit)
526+
params = build_params(query=query, user=user, limit=limit)
530527
data = self._requester.request("GET", "/sessions/search", params=params or None)
531528
return SessionSearchResult.model_validate(data)

src/client/acontext-ts/src/resources/sessions.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -444,34 +444,29 @@ export class SessionsAPI {
444444
*
445445
* @param options - Options for searching sessions.
446446
* @param options.query - The search query text.
447-
* @param options.userId - The User ID to search within.
448-
* @param options.projectId - The Project ID to search within.
447+
* @param options.user - User identifier to scope the search (e.g., email address).
449448
* @param options.limit - Maximum number of results to return (1-100, default 10).
450449
* @returns SessionSearchResult containing list of matching session UUIDs.
451450
*
452451
* @example
453452
* const result = await client.sessions.search({
454453
* query: 'conversations about authentication',
455-
* userId: 'user_123',
456-
* projectId: 'proj_456'
454+
* user: 'alice@acontext.io'
457455
* });
458456
*/
459457
async search(options: {
460458
query: string;
461-
userId: string;
462-
projectId: string;
459+
user: string;
463460
limit?: number | null;
464461
}): Promise<{ session_ids: string[] }> {
465462
const params = buildParams({
466463
query: options.query,
467-
user_id: options.userId,
468-
project_id: options.projectId,
464+
user: options.user,
469465
limit: options.limit ?? null,
470466
});
471467
const data = await this.requester.request('GET', '/sessions/search', {
472468
params: Object.keys(params).length > 0 ? params : undefined,
473469
});
474-
// Assuming SessionSearchResult schema exists or returning generic object
475470
return data as { session_ids: string[] };
476471
}
477472
}

src/server/api/go/internal/modules/handler/session.go

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -780,10 +780,9 @@ func (h *SessionHandler) PatchConfigs(c *gin.Context) {
780780
}
781781

782782
type SessionSearchReq struct {
783-
Query string `form:"query" json:"query" binding:"required" example:"find conversations about authentication"`
784-
UserID string `form:"user_id" json:"user_id" binding:"required" example:"123e4567-e89b-12d3-a456-426614174000"`
785-
ProjectID string `form:"project_id" json:"project_id" binding:"required" example:"123e4567-e89b-12d3-a456-426614174001"`
786-
Limit int `form:"limit,default=10" json:"limit" binding:"omitempty,min=1,max=100" example:"10"`
783+
Query string `form:"query" json:"query" binding:"required" example:"find conversations about authentication"`
784+
User string `form:"user" json:"user" binding:"required" example:"alice@acontext.io"`
785+
Limit int `form:"limit,default=10" json:"limit" binding:"omitempty,min=1,max=100" example:"10"`
787786
}
788787

789788
// SessionSearch godoc
@@ -794,8 +793,7 @@ type SessionSearchReq struct {
794793
// @Accept json
795794
// @Produce json
796795
// @Param query query string true "Search query text"
797-
// @Param user_id query string true "User ID"
798-
// @Param project_id query string true "Project ID"
796+
// @Param user query string true "user identifier" example(alice@acontext.io)
799797
// @Param limit query integer false "Maximum number of results (1-100, default 10)"
800798
// @Security BearerAuth
801799
// @Success 200 {object} serializer.Response{data=httpclient.SessionSearchResponse}
@@ -807,12 +805,24 @@ func (h *SessionHandler) SessionSearch(c *gin.Context) {
807805
return
808806
}
809807

808+
project, ok := c.MustGet("project").(*model.Project)
809+
if !ok {
810+
c.JSON(http.StatusBadRequest, serializer.ParamErr("", errors.New("project not found")))
811+
return
812+
}
813+
814+
user, err := h.userSvc.GetByIdentifier(c.Request.Context(), project.ID, req.User)
815+
if err != nil {
816+
c.JSON(http.StatusNotFound, serializer.Err(http.StatusNotFound, "user not found in this project", err))
817+
return
818+
}
819+
810820
limit := req.Limit
811821
if limit == 0 {
812822
limit = 10
813823
}
814824

815-
result, err := h.coreClient.SessionSearch(c.Request.Context(), req.UserID, req.ProjectID, req.Query, limit)
825+
result, err := h.coreClient.SessionSearch(c.Request.Context(), user.ID.String(), project.ID.String(), req.Query, limit)
816826
if err != nil {
817827
c.JSON(http.StatusInternalServerError, serializer.Err(http.StatusInternalServerError, "failed to search sessions", err))
818828
return

src/server/api/go/internal/modules/handler/user_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ func (m *MockUserService) GetOrCreate(ctx context.Context, projectID uuid.UUID,
3030
return args.Get(0).(*model.User), args.Error(1)
3131
}
3232

33+
func (m *MockUserService) GetByIdentifier(ctx context.Context, projectID uuid.UUID, identifier string) (*model.User, error) {
34+
args := m.Called(ctx, projectID, identifier)
35+
if args.Get(0) == nil {
36+
return nil, args.Error(1)
37+
}
38+
return args.Get(0).(*model.User), args.Error(1)
39+
}
40+
3341
func (m *MockUserService) Delete(ctx context.Context, projectID uuid.UUID, identifier string) error {
3442
args := m.Called(ctx, projectID, identifier)
3543
return args.Error(0)

src/server/api/go/internal/modules/service/user.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313

1414
type UserService interface {
1515
GetOrCreate(ctx context.Context, projectID uuid.UUID, identifier string) (*model.User, error)
16+
GetByIdentifier(ctx context.Context, projectID uuid.UUID, identifier string) (*model.User, error)
1617
Delete(ctx context.Context, projectID uuid.UUID, identifier string) error
1718
List(ctx context.Context, in ListUsersInput) (*ListUsersOutput, error)
1819
GetResourceCounts(ctx context.Context, projectID uuid.UUID, identifier string) (*GetUserResourcesOutput, error)
@@ -33,6 +34,13 @@ func (s *userService) GetOrCreate(ctx context.Context, projectID uuid.UUID, iden
3334
return s.r.GetOrCreate(ctx, projectID, identifier)
3435
}
3536

37+
func (s *userService) GetByIdentifier(ctx context.Context, projectID uuid.UUID, identifier string) (*model.User, error) {
38+
if identifier == "" {
39+
return nil, errors.New("user identifier is empty")
40+
}
41+
return s.r.GetByIdentifier(ctx, projectID, identifier)
42+
}
43+
3644
func (s *userService) Delete(ctx context.Context, projectID uuid.UUID, identifier string) error {
3745
if identifier == "" {
3846
return errors.New("user identifier is empty")

0 commit comments

Comments
 (0)