Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions session/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
17 changes: 17 additions & 0 deletions session/session_test/service_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
3 changes: 2 additions & 1 deletion session/vertexai/vertexai_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
45 changes: 45 additions & 0 deletions session/vertexai/vertexai_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down