diff --git a/session/service.go b/session/service.go index 3cf09e360..b653afd13 100644 --- a/session/service.go +++ b/session/service.go @@ -48,6 +48,9 @@ type CreateRequest struct { SessionID string // State is the initial state of the session. State map[string]any + // DisplayName is a human-readable name for the session. + // Optional: only used by backends that support it (e.g. Vertex AI). + DisplayName string } // CreateResponse represents a response for newly created session. diff --git a/session/session_test/service_suite.go b/session/session_test/service_suite.go index ff3b51bb0..4458668d6 100644 --- a/session/session_test/service_suite.go +++ b/session/session_test/service_suite.go @@ -131,6 +131,23 @@ func RunServiceTests(t *testing.T, opts SuiteOptions, setup func(t *testing.T) s } }) + t.Run("with_display_name", func(t *testing.T) { + s := setup(t) + req := &session.CreateRequest{ + AppName: testAppName, + UserID: "testUserID", + DisplayName: "My Chat Session", + } + + got, err := s.Create(t.Context(), req) + if err != nil { + t.Fatalf("Create() with DisplayName error = %v", err) + } + if got.Session.ID() == "" { + t.Errorf("Expected generated SessionID, got empty") + } + }) + t.Run("when_already_exists,_it_fails", func(t *testing.T) { s := setup(t) req := &session.CreateRequest{ diff --git a/session/vertexai/vertexai_client.go b/session/vertexai/vertexai_client.go index 04f1b5000..dca6cb2c5 100644 --- a/session/vertexai/vertexai_client.go +++ b/session/vertexai/vertexai_client.go @@ -64,7 +64,8 @@ func (c *vertexAiClient) Close() error { func (c *vertexAiClient) createSession(ctx context.Context, req *session.CreateRequest) (*localSession, error) { pbSession := &aiplatformpb.Session{ - UserId: req.UserID, + UserId: req.UserID, + DisplayName: req.DisplayName, } // Convert and set the initial state if provided if len(req.State) > 0 { diff --git a/session/vertexai/vertexai_test.go b/session/vertexai/vertexai_test.go index 2e4b9251a..c3a30573f 100644 --- a/session/vertexai/vertexai_test.go +++ b/session/vertexai/vertexai_test.go @@ -16,8 +16,53 @@ package vertexai import ( "testing" + + aiplatformpb "cloud.google.com/go/aiplatform/apiv1beta1/aiplatformpb" + "google.golang.org/adk/session" ) +func TestCreateSessionProto_DisplayName(t *testing.T) { + tests := []struct { + name string + displayName string + wantProto string + }{ + { + name: "display name is set on proto", + displayName: "My Chat", + wantProto: "My Chat", + }, + { + name: "empty display name results in empty proto field", + displayName: "", + wantProto: "", + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + req := &session.CreateRequest{ + AppName: "testApp", + UserID: "user-1", + DisplayName: tt.displayName, + } + + // Replicate the proto construction from createSession. + pbSession := &aiplatformpb.Session{ + UserId: req.UserID, + DisplayName: req.DisplayName, + } + + if pbSession.DisplayName != tt.wantProto { + t.Errorf("DisplayName = %q, want %q", pbSession.DisplayName, tt.wantProto) + } + if pbSession.UserId != req.UserID { + t.Errorf("UserId = %q, want %q", pbSession.UserId, req.UserID) + } + }) + } +} + func TestGetReasoningEngineID(t *testing.T) { tests := []struct { name string