Skip to content

Commit a93f1bf

Browse files
feat: Added optional param to force empty object
1 parent 0c7cb02 commit a93f1bf

File tree

7 files changed

+233
-69
lines changed

7 files changed

+233
-69
lines changed

.stats.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 7
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/browserbase%2Fstagehand-2c6c017cc9ca1fcfe7b3902edfa64fb0420bdb46b1740c7c862e81e2132d4f7c.yml
3-
openapi_spec_hash: 220daf7e8f5897909a6c10e3385386e3
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/browserbase%2Fstagehand-39cd9547d16412cf0568f6ce2ad8d43805dffe65bde830beeff630b903ae3b38.yml
3+
openapi_spec_hash: 9cd7c9fefa686f9711392782d948470f
44
config_hash: 1f709f8775e13029dc60064ef3a94355

stagehand-java-core/src/main/kotlin/com/browserbase/api/models/sessions/SessionEndParams.kt

Lines changed: 163 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,21 @@
33
package com.browserbase.api.models.sessions
44

55
import com.browserbase.api.core.Enum
6+
import com.browserbase.api.core.ExcludeMissing
67
import com.browserbase.api.core.JsonField
8+
import com.browserbase.api.core.JsonMissing
79
import com.browserbase.api.core.JsonValue
810
import com.browserbase.api.core.Params
9-
import com.browserbase.api.core.checkRequired
1011
import com.browserbase.api.core.http.Headers
1112
import com.browserbase.api.core.http.QueryParams
1213
import com.browserbase.api.errors.StagehandInvalidDataException
14+
import com.fasterxml.jackson.annotation.JsonAnyGetter
15+
import com.fasterxml.jackson.annotation.JsonAnySetter
1316
import com.fasterxml.jackson.annotation.JsonCreator
17+
import com.fasterxml.jackson.annotation.JsonProperty
1418
import java.time.OffsetDateTime
1519
import java.time.format.DateTimeFormatter
20+
import java.util.Collections
1621
import java.util.Objects
1722
import java.util.Optional
1823
import kotlin.jvm.optionals.getOrNull
@@ -25,7 +30,7 @@ private constructor(
2530
private val xSdkVersion: String?,
2631
private val xSentAt: OffsetDateTime?,
2732
private val xStreamResponse: XStreamResponse?,
28-
private val body: JsonValue,
33+
private val body: Body,
2934
private val additionalHeaders: Headers,
3035
private val additionalQueryParams: QueryParams,
3136
) : Params {
@@ -45,7 +50,9 @@ private constructor(
4550
/** Whether to stream the response via SSE */
4651
fun xStreamResponse(): Optional<XStreamResponse> = Optional.ofNullable(xStreamResponse)
4752

48-
fun body(): JsonValue = body
53+
fun __forceBody(): JsonValue = body.__forceBody()
54+
55+
fun _additionalBodyProperties(): Map<String, JsonValue> = body._additionalProperties()
4956

5057
/** Additional headers to send with the request. */
5158
fun _additionalHeaders(): Headers = additionalHeaders
@@ -57,14 +64,9 @@ private constructor(
5764

5865
companion object {
5966

60-
/**
61-
* Returns a mutable builder for constructing an instance of [SessionEndParams].
62-
*
63-
* The following fields are required:
64-
* ```java
65-
* .body()
66-
* ```
67-
*/
67+
@JvmStatic fun none(): SessionEndParams = builder().build()
68+
69+
/** Returns a mutable builder for constructing an instance of [SessionEndParams]. */
6870
@JvmStatic fun builder() = Builder()
6971
}
7072

@@ -76,7 +78,7 @@ private constructor(
7678
private var xSdkVersion: String? = null
7779
private var xSentAt: OffsetDateTime? = null
7880
private var xStreamResponse: XStreamResponse? = null
79-
private var body: JsonValue? = null
81+
private var body: Body.Builder = Body.builder()
8082
private var additionalHeaders: Headers.Builder = Headers.builder()
8183
private var additionalQueryParams: QueryParams.Builder = QueryParams.builder()
8284

@@ -87,7 +89,7 @@ private constructor(
8789
xSdkVersion = sessionEndParams.xSdkVersion
8890
xSentAt = sessionEndParams.xSentAt
8991
xStreamResponse = sessionEndParams.xStreamResponse
90-
body = sessionEndParams.body
92+
body = sessionEndParams.body.toBuilder()
9193
additionalHeaders = sessionEndParams.additionalHeaders.toBuilder()
9294
additionalQueryParams = sessionEndParams.additionalQueryParams.toBuilder()
9395
}
@@ -125,7 +127,35 @@ private constructor(
125127
fun xStreamResponse(xStreamResponse: Optional<XStreamResponse>) =
126128
xStreamResponse(xStreamResponse.getOrNull())
127129

128-
fun body(body: JsonValue) = apply { this.body = body }
130+
/**
131+
* Sets the entire request body.
132+
*
133+
* This is generally only useful if you are already constructing the body separately.
134+
* Otherwise, it's more convenient to use the top-level setters instead:
135+
* - [_forceBody]
136+
*/
137+
fun body(body: Body) = apply { this.body = body.toBuilder() }
138+
139+
fun _forceBody(_forceBody: JsonValue) = apply { body._forceBody(_forceBody) }
140+
141+
fun additionalBodyProperties(additionalBodyProperties: Map<String, JsonValue>) = apply {
142+
body.additionalProperties(additionalBodyProperties)
143+
}
144+
145+
fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply {
146+
body.putAdditionalProperty(key, value)
147+
}
148+
149+
fun putAllAdditionalBodyProperties(additionalBodyProperties: Map<String, JsonValue>) =
150+
apply {
151+
body.putAllAdditionalProperties(additionalBodyProperties)
152+
}
153+
154+
fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) }
155+
156+
fun removeAllAdditionalBodyProperties(keys: Set<String>) = apply {
157+
body.removeAllAdditionalProperties(keys)
158+
}
129159

130160
fun additionalHeaders(additionalHeaders: Headers) = apply {
131161
this.additionalHeaders.clear()
@@ -229,13 +259,6 @@ private constructor(
229259
* Returns an immutable instance of [SessionEndParams].
230260
*
231261
* Further updates to this [Builder] will not mutate the returned instance.
232-
*
233-
* The following fields are required:
234-
* ```java
235-
* .body()
236-
* ```
237-
*
238-
* @throws IllegalStateException if any required field is unset.
239262
*/
240263
fun build(): SessionEndParams =
241264
SessionEndParams(
@@ -244,13 +267,13 @@ private constructor(
244267
xSdkVersion,
245268
xSentAt,
246269
xStreamResponse,
247-
checkRequired("body", body),
270+
body.build(),
248271
additionalHeaders.build(),
249272
additionalQueryParams.build(),
250273
)
251274
}
252275

253-
fun _body(): JsonValue = body
276+
fun _body(): Body = body
254277

255278
fun _pathParam(index: Int): String =
256279
when (index) {
@@ -271,6 +294,123 @@ private constructor(
271294

272295
override fun _queryParams(): QueryParams = additionalQueryParams
273296

297+
class Body
298+
@JsonCreator(mode = JsonCreator.Mode.DISABLED)
299+
private constructor(
300+
private val _forceBody: JsonValue,
301+
private val additionalProperties: MutableMap<String, JsonValue>,
302+
) {
303+
304+
@JsonCreator
305+
private constructor(
306+
@JsonProperty("_forceBody") @ExcludeMissing _forceBody: JsonValue = JsonMissing.of()
307+
) : this(_forceBody, mutableMapOf())
308+
309+
@JsonProperty("_forceBody") @ExcludeMissing fun __forceBody(): JsonValue = _forceBody
310+
311+
@JsonAnySetter
312+
private fun putAdditionalProperty(key: String, value: JsonValue) {
313+
additionalProperties.put(key, value)
314+
}
315+
316+
@JsonAnyGetter
317+
@ExcludeMissing
318+
fun _additionalProperties(): Map<String, JsonValue> =
319+
Collections.unmodifiableMap(additionalProperties)
320+
321+
fun toBuilder() = Builder().from(this)
322+
323+
companion object {
324+
325+
/** Returns a mutable builder for constructing an instance of [Body]. */
326+
@JvmStatic fun builder() = Builder()
327+
}
328+
329+
/** A builder for [Body]. */
330+
class Builder internal constructor() {
331+
332+
private var _forceBody: JsonValue = JsonMissing.of()
333+
private var additionalProperties: MutableMap<String, JsonValue> = mutableMapOf()
334+
335+
@JvmSynthetic
336+
internal fun from(body: Body) = apply {
337+
_forceBody = body._forceBody
338+
additionalProperties = body.additionalProperties.toMutableMap()
339+
}
340+
341+
fun _forceBody(_forceBody: JsonValue) = apply { this._forceBody = _forceBody }
342+
343+
fun additionalProperties(additionalProperties: Map<String, JsonValue>) = apply {
344+
this.additionalProperties.clear()
345+
putAllAdditionalProperties(additionalProperties)
346+
}
347+
348+
fun putAdditionalProperty(key: String, value: JsonValue) = apply {
349+
additionalProperties.put(key, value)
350+
}
351+
352+
fun putAllAdditionalProperties(additionalProperties: Map<String, JsonValue>) = apply {
353+
this.additionalProperties.putAll(additionalProperties)
354+
}
355+
356+
fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) }
357+
358+
fun removeAllAdditionalProperties(keys: Set<String>) = apply {
359+
keys.forEach(::removeAdditionalProperty)
360+
}
361+
362+
/**
363+
* Returns an immutable instance of [Body].
364+
*
365+
* Further updates to this [Builder] will not mutate the returned instance.
366+
*/
367+
fun build(): Body = Body(_forceBody, additionalProperties.toMutableMap())
368+
}
369+
370+
private var validated: Boolean = false
371+
372+
fun validate(): Body = apply {
373+
if (validated) {
374+
return@apply
375+
}
376+
377+
validated = true
378+
}
379+
380+
fun isValid(): Boolean =
381+
try {
382+
validate()
383+
true
384+
} catch (e: StagehandInvalidDataException) {
385+
false
386+
}
387+
388+
/**
389+
* Returns a score indicating how many valid values are contained in this object
390+
* recursively.
391+
*
392+
* Used for best match union deserialization.
393+
*/
394+
@JvmSynthetic internal fun validity(): Int = 0
395+
396+
override fun equals(other: Any?): Boolean {
397+
if (this === other) {
398+
return true
399+
}
400+
401+
return other is Body &&
402+
_forceBody == other._forceBody &&
403+
additionalProperties == other.additionalProperties
404+
}
405+
406+
private val hashCode: Int by lazy { Objects.hash(_forceBody, additionalProperties) }
407+
408+
override fun hashCode(): Int = hashCode
409+
410+
override fun toString() =
411+
"Body{_forceBody=$_forceBody, additionalProperties=$additionalProperties}"
412+
}
413+
274414
/** Client SDK language */
275415
class XLanguage @JsonCreator private constructor(private val value: JsonField<String>) : Enum {
276416

stagehand-java-core/src/main/kotlin/com/browserbase/api/services/async/SessionServiceAsync.kt

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -89,27 +89,36 @@ interface SessionServiceAsync {
8989
): AsyncStreamResponse<StreamEvent>
9090

9191
/** Terminates the browser session and releases all associated resources. */
92-
fun end(id: String, params: SessionEndParams): CompletableFuture<SessionEndResponse> =
93-
end(id, params, RequestOptions.none())
92+
fun end(id: String): CompletableFuture<SessionEndResponse> = end(id, SessionEndParams.none())
9493

9594
/** @see end */
9695
fun end(
9796
id: String,
98-
params: SessionEndParams,
97+
params: SessionEndParams = SessionEndParams.none(),
9998
requestOptions: RequestOptions = RequestOptions.none(),
10099
): CompletableFuture<SessionEndResponse> =
101100
end(params.toBuilder().id(id).build(), requestOptions)
102101

103102
/** @see end */
104-
fun end(params: SessionEndParams): CompletableFuture<SessionEndResponse> =
105-
end(params, RequestOptions.none())
103+
fun end(
104+
id: String,
105+
params: SessionEndParams = SessionEndParams.none(),
106+
): CompletableFuture<SessionEndResponse> = end(id, params, RequestOptions.none())
106107

107108
/** @see end */
108109
fun end(
109110
params: SessionEndParams,
110111
requestOptions: RequestOptions = RequestOptions.none(),
111112
): CompletableFuture<SessionEndResponse>
112113

114+
/** @see end */
115+
fun end(params: SessionEndParams): CompletableFuture<SessionEndResponse> =
116+
end(params, RequestOptions.none())
117+
118+
/** @see end */
119+
fun end(id: String, requestOptions: RequestOptions): CompletableFuture<SessionEndResponse> =
120+
end(id, SessionEndParams.none(), requestOptions)
121+
113122
/** Runs an autonomous AI agent that can perform complex multi-step browser tasks. */
114123
fun execute(
115124
id: String,
@@ -421,29 +430,40 @@ interface SessionServiceAsync {
421430
* Returns a raw HTTP response for `post /v1/sessions/{id}/end`, but is otherwise the same
422431
* as [SessionServiceAsync.end].
423432
*/
433+
fun end(id: String): CompletableFuture<HttpResponseFor<SessionEndResponse>> =
434+
end(id, SessionEndParams.none())
435+
436+
/** @see end */
424437
fun end(
425438
id: String,
426-
params: SessionEndParams,
439+
params: SessionEndParams = SessionEndParams.none(),
440+
requestOptions: RequestOptions = RequestOptions.none(),
427441
): CompletableFuture<HttpResponseFor<SessionEndResponse>> =
428-
end(id, params, RequestOptions.none())
442+
end(params.toBuilder().id(id).build(), requestOptions)
429443

430444
/** @see end */
431445
fun end(
432446
id: String,
447+
params: SessionEndParams = SessionEndParams.none(),
448+
): CompletableFuture<HttpResponseFor<SessionEndResponse>> =
449+
end(id, params, RequestOptions.none())
450+
451+
/** @see end */
452+
fun end(
433453
params: SessionEndParams,
434454
requestOptions: RequestOptions = RequestOptions.none(),
435-
): CompletableFuture<HttpResponseFor<SessionEndResponse>> =
436-
end(params.toBuilder().id(id).build(), requestOptions)
455+
): CompletableFuture<HttpResponseFor<SessionEndResponse>>
437456

438457
/** @see end */
439458
fun end(params: SessionEndParams): CompletableFuture<HttpResponseFor<SessionEndResponse>> =
440459
end(params, RequestOptions.none())
441460

442461
/** @see end */
443462
fun end(
444-
params: SessionEndParams,
445-
requestOptions: RequestOptions = RequestOptions.none(),
446-
): CompletableFuture<HttpResponseFor<SessionEndResponse>>
463+
id: String,
464+
requestOptions: RequestOptions,
465+
): CompletableFuture<HttpResponseFor<SessionEndResponse>> =
466+
end(id, SessionEndParams.none(), requestOptions)
447467

448468
/**
449469
* Returns a raw HTTP response for `post /v1/sessions/{id}/agentExecute`, but is otherwise

0 commit comments

Comments
 (0)