Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.google.adk.sessions.BaseSessionService;
import com.google.adk.sessions.ListSessionsResponse;
import com.google.adk.sessions.Session;
import com.google.adk.web.dto.SessionRequest;
import io.reactivex.rxjava3.core.Maybe;
import io.reactivex.rxjava3.core.Single;
import java.util.Collections;
Expand Down Expand Up @@ -167,13 +168,15 @@ public Session createSessionWithId(
@PathVariable String appName,
@PathVariable String userId,
@PathVariable String sessionId,
@RequestBody(required = false) Map<String, Object> state) {
@RequestBody(required = false) SessionRequest body) {
log.info(
"Request received for POST /apps/{}/users/{}/sessions/{} with state: {}",
"Request received for POST /apps/{}/users/{}/sessions/{} with request body: {}",
appName,
userId,
sessionId,
state);
body);

Map<String, Object> initialState = (body != null) ? body.getState() : Collections.emptyMap();

try {
findSessionOrThrow(appName, userId, sessionId);
Expand All @@ -190,7 +193,6 @@ public Session createSessionWithId(
log.info("Session {} not found, proceeding with creation.", sessionId);
}

Map<String, Object> initialState = (state != null) ? state : Collections.emptyMap();
try {
Session createdSession =
sessionService
Expand Down Expand Up @@ -228,18 +230,17 @@ public Session createSessionWithId(
public Session createSession(
@PathVariable String appName,
@PathVariable String userId,
@RequestBody(required = false) Map<String, Object> state) {
@RequestBody(required = false) SessionRequest body) {

log.info(
"Request received for POST /apps/{}/users/{}/sessions (service generates ID) with state:"
+ " {}",
"Request received for POST /apps/{}/users/{}/sessions (service generates ID) with request"
+ " body: {}",
appName,
userId,
state);
body);

Map<String, Object> initialState = (state != null) ? state : Collections.emptyMap();
try {

Map<String, Object> initialState = (body != null) ? body.getState() : Collections.emptyMap();
Session createdSession =
sessionService
.createSession(appName, userId, new ConcurrentHashMap<>(initialState), null)
Expand Down
39 changes: 39 additions & 0 deletions dev/src/main/java/com/google/adk/web/dto/SessionRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright 2025 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.adk.web.dto;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.collect.ImmutableMap;
import java.util.Map;

/**
* Data Transfer Object (DTO) for POST /apps/{appName}/users/{userId}/sessions and POST
* /apps/{appName}/users/{userId}/sessions/{sessionId} equests. Contains information for a session.
*/
public final class SessionRequest {
private final ImmutableMap<String, Object> state;

@JsonCreator
public SessionRequest(@JsonProperty("state") Map<String, Object> state) {
this.state = (state == null) ? ImmutableMap.of() : ImmutableMap.copyOf(state);
}

public ImmutableMap<String, Object> getState() {
return state;
}
}