Skip to content

Commit e307cff

Browse files
feat: Include replay endpoint in stainless spec so SDK clients can get run metrics
1 parent 769ed85 commit e307cff

File tree

11 files changed

+1854
-4
lines changed

11 files changed

+1854
-4
lines changed

.stats.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
configured_endpoints: 7
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/browserbase%2Fstagehand-1c405024b4a17886e921871250a445362463b7ae6070cacc3d1927d59036730c.yml
3-
openapi_spec_hash: c4ea3735257a48ed105002eb7aaa095a
4-
config_hash: 85d56c7c196269badbd0b4a9dfb28d45
1+
configured_endpoints: 8
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/browserbase%2Fstagehand-089c8670f1d7c2e9fa8e5c97010db7c24b8f162eb7cfe76ffa41d70fa46efe2f.yml
3+
openapi_spec_hash: 7a226aee8f3f2ab16febbe6bb35e1657
4+
config_hash: 8e4ed6629c178aa0c8aaf575cb07c544
Lines changed: 355 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,355 @@
1+
// File generated from our OpenAPI spec by Stainless.
2+
3+
package com.browserbase.api.models.sessions
4+
5+
import com.browserbase.api.core.Enum
6+
import com.browserbase.api.core.JsonField
7+
import com.browserbase.api.core.Params
8+
import com.browserbase.api.core.http.Headers
9+
import com.browserbase.api.core.http.QueryParams
10+
import com.browserbase.api.errors.StagehandInvalidDataException
11+
import com.fasterxml.jackson.annotation.JsonCreator
12+
import java.util.Objects
13+
import java.util.Optional
14+
import kotlin.jvm.optionals.getOrNull
15+
16+
/** Retrieves replay metrics for a session. */
17+
class SessionReplayParams
18+
private constructor(
19+
private val id: String?,
20+
private val xStreamResponse: XStreamResponse?,
21+
private val additionalHeaders: Headers,
22+
private val additionalQueryParams: QueryParams,
23+
) : Params {
24+
25+
/** Unique session identifier */
26+
fun id(): Optional<String> = Optional.ofNullable(id)
27+
28+
/** Whether to stream the response via SSE */
29+
fun xStreamResponse(): Optional<XStreamResponse> = Optional.ofNullable(xStreamResponse)
30+
31+
/** Additional headers to send with the request. */
32+
fun _additionalHeaders(): Headers = additionalHeaders
33+
34+
/** Additional query param to send with the request. */
35+
fun _additionalQueryParams(): QueryParams = additionalQueryParams
36+
37+
fun toBuilder() = Builder().from(this)
38+
39+
companion object {
40+
41+
@JvmStatic fun none(): SessionReplayParams = builder().build()
42+
43+
/** Returns a mutable builder for constructing an instance of [SessionReplayParams]. */
44+
@JvmStatic fun builder() = Builder()
45+
}
46+
47+
/** A builder for [SessionReplayParams]. */
48+
class Builder internal constructor() {
49+
50+
private var id: String? = null
51+
private var xStreamResponse: XStreamResponse? = null
52+
private var additionalHeaders: Headers.Builder = Headers.builder()
53+
private var additionalQueryParams: QueryParams.Builder = QueryParams.builder()
54+
55+
@JvmSynthetic
56+
internal fun from(sessionReplayParams: SessionReplayParams) = apply {
57+
id = sessionReplayParams.id
58+
xStreamResponse = sessionReplayParams.xStreamResponse
59+
additionalHeaders = sessionReplayParams.additionalHeaders.toBuilder()
60+
additionalQueryParams = sessionReplayParams.additionalQueryParams.toBuilder()
61+
}
62+
63+
/** Unique session identifier */
64+
fun id(id: String?) = apply { this.id = id }
65+
66+
/** Alias for calling [Builder.id] with `id.orElse(null)`. */
67+
fun id(id: Optional<String>) = id(id.getOrNull())
68+
69+
/** Whether to stream the response via SSE */
70+
fun xStreamResponse(xStreamResponse: XStreamResponse?) = apply {
71+
this.xStreamResponse = xStreamResponse
72+
}
73+
74+
/** Alias for calling [Builder.xStreamResponse] with `xStreamResponse.orElse(null)`. */
75+
fun xStreamResponse(xStreamResponse: Optional<XStreamResponse>) =
76+
xStreamResponse(xStreamResponse.getOrNull())
77+
78+
fun additionalHeaders(additionalHeaders: Headers) = apply {
79+
this.additionalHeaders.clear()
80+
putAllAdditionalHeaders(additionalHeaders)
81+
}
82+
83+
fun additionalHeaders(additionalHeaders: Map<String, Iterable<String>>) = apply {
84+
this.additionalHeaders.clear()
85+
putAllAdditionalHeaders(additionalHeaders)
86+
}
87+
88+
fun putAdditionalHeader(name: String, value: String) = apply {
89+
additionalHeaders.put(name, value)
90+
}
91+
92+
fun putAdditionalHeaders(name: String, values: Iterable<String>) = apply {
93+
additionalHeaders.put(name, values)
94+
}
95+
96+
fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply {
97+
this.additionalHeaders.putAll(additionalHeaders)
98+
}
99+
100+
fun putAllAdditionalHeaders(additionalHeaders: Map<String, Iterable<String>>) = apply {
101+
this.additionalHeaders.putAll(additionalHeaders)
102+
}
103+
104+
fun replaceAdditionalHeaders(name: String, value: String) = apply {
105+
additionalHeaders.replace(name, value)
106+
}
107+
108+
fun replaceAdditionalHeaders(name: String, values: Iterable<String>) = apply {
109+
additionalHeaders.replace(name, values)
110+
}
111+
112+
fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply {
113+
this.additionalHeaders.replaceAll(additionalHeaders)
114+
}
115+
116+
fun replaceAllAdditionalHeaders(additionalHeaders: Map<String, Iterable<String>>) = apply {
117+
this.additionalHeaders.replaceAll(additionalHeaders)
118+
}
119+
120+
fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) }
121+
122+
fun removeAllAdditionalHeaders(names: Set<String>) = apply {
123+
additionalHeaders.removeAll(names)
124+
}
125+
126+
fun additionalQueryParams(additionalQueryParams: QueryParams) = apply {
127+
this.additionalQueryParams.clear()
128+
putAllAdditionalQueryParams(additionalQueryParams)
129+
}
130+
131+
fun additionalQueryParams(additionalQueryParams: Map<String, Iterable<String>>) = apply {
132+
this.additionalQueryParams.clear()
133+
putAllAdditionalQueryParams(additionalQueryParams)
134+
}
135+
136+
fun putAdditionalQueryParam(key: String, value: String) = apply {
137+
additionalQueryParams.put(key, value)
138+
}
139+
140+
fun putAdditionalQueryParams(key: String, values: Iterable<String>) = apply {
141+
additionalQueryParams.put(key, values)
142+
}
143+
144+
fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply {
145+
this.additionalQueryParams.putAll(additionalQueryParams)
146+
}
147+
148+
fun putAllAdditionalQueryParams(additionalQueryParams: Map<String, Iterable<String>>) =
149+
apply {
150+
this.additionalQueryParams.putAll(additionalQueryParams)
151+
}
152+
153+
fun replaceAdditionalQueryParams(key: String, value: String) = apply {
154+
additionalQueryParams.replace(key, value)
155+
}
156+
157+
fun replaceAdditionalQueryParams(key: String, values: Iterable<String>) = apply {
158+
additionalQueryParams.replace(key, values)
159+
}
160+
161+
fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply {
162+
this.additionalQueryParams.replaceAll(additionalQueryParams)
163+
}
164+
165+
fun replaceAllAdditionalQueryParams(additionalQueryParams: Map<String, Iterable<String>>) =
166+
apply {
167+
this.additionalQueryParams.replaceAll(additionalQueryParams)
168+
}
169+
170+
fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) }
171+
172+
fun removeAllAdditionalQueryParams(keys: Set<String>) = apply {
173+
additionalQueryParams.removeAll(keys)
174+
}
175+
176+
/**
177+
* Returns an immutable instance of [SessionReplayParams].
178+
*
179+
* Further updates to this [Builder] will not mutate the returned instance.
180+
*/
181+
fun build(): SessionReplayParams =
182+
SessionReplayParams(
183+
id,
184+
xStreamResponse,
185+
additionalHeaders.build(),
186+
additionalQueryParams.build(),
187+
)
188+
}
189+
190+
fun _pathParam(index: Int): String =
191+
when (index) {
192+
0 -> id ?: ""
193+
else -> ""
194+
}
195+
196+
override fun _headers(): Headers =
197+
Headers.builder()
198+
.apply {
199+
xStreamResponse?.let { put("x-stream-response", it.toString()) }
200+
putAll(additionalHeaders)
201+
}
202+
.build()
203+
204+
override fun _queryParams(): QueryParams = additionalQueryParams
205+
206+
/** Whether to stream the response via SSE */
207+
class XStreamResponse @JsonCreator private constructor(private val value: JsonField<String>) :
208+
Enum {
209+
210+
/**
211+
* Returns this class instance's raw value.
212+
*
213+
* This is usually only useful if this instance was deserialized from data that doesn't
214+
* match any known member, and you want to know that value. For example, if the SDK is on an
215+
* older version than the API, then the API may respond with new members that the SDK is
216+
* unaware of.
217+
*/
218+
@com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField<String> = value
219+
220+
companion object {
221+
222+
@JvmField val TRUE = of("true")
223+
224+
@JvmField val FALSE = of("false")
225+
226+
@JvmStatic fun of(value: String) = XStreamResponse(JsonField.of(value))
227+
}
228+
229+
/** An enum containing [XStreamResponse]'s known values. */
230+
enum class Known {
231+
TRUE,
232+
FALSE,
233+
}
234+
235+
/**
236+
* An enum containing [XStreamResponse]'s known values, as well as an [_UNKNOWN] member.
237+
*
238+
* An instance of [XStreamResponse] can contain an unknown value in a couple of cases:
239+
* - It was deserialized from data that doesn't match any known member. For example, if the
240+
* SDK is on an older version than the API, then the API may respond with new members that
241+
* the SDK is unaware of.
242+
* - It was constructed with an arbitrary value using the [of] method.
243+
*/
244+
enum class Value {
245+
TRUE,
246+
FALSE,
247+
/**
248+
* An enum member indicating that [XStreamResponse] was instantiated with an unknown
249+
* value.
250+
*/
251+
_UNKNOWN,
252+
}
253+
254+
/**
255+
* Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN]
256+
* if the class was instantiated with an unknown value.
257+
*
258+
* Use the [known] method instead if you're certain the value is always known or if you want
259+
* to throw for the unknown case.
260+
*/
261+
fun value(): Value =
262+
when (this) {
263+
TRUE -> Value.TRUE
264+
FALSE -> Value.FALSE
265+
else -> Value._UNKNOWN
266+
}
267+
268+
/**
269+
* Returns an enum member corresponding to this class instance's value.
270+
*
271+
* Use the [value] method instead if you're uncertain the value is always known and don't
272+
* want to throw for the unknown case.
273+
*
274+
* @throws StagehandInvalidDataException if this class instance's value is a not a known
275+
* member.
276+
*/
277+
fun known(): Known =
278+
when (this) {
279+
TRUE -> Known.TRUE
280+
FALSE -> Known.FALSE
281+
else -> throw StagehandInvalidDataException("Unknown XStreamResponse: $value")
282+
}
283+
284+
/**
285+
* Returns this class instance's primitive wire representation.
286+
*
287+
* This differs from the [toString] method because that method is primarily for debugging
288+
* and generally doesn't throw.
289+
*
290+
* @throws StagehandInvalidDataException if this class instance's value does not have the
291+
* expected primitive type.
292+
*/
293+
fun asString(): String =
294+
_value().asString().orElseThrow {
295+
StagehandInvalidDataException("Value is not a String")
296+
}
297+
298+
private var validated: Boolean = false
299+
300+
fun validate(): XStreamResponse = apply {
301+
if (validated) {
302+
return@apply
303+
}
304+
305+
known()
306+
validated = true
307+
}
308+
309+
fun isValid(): Boolean =
310+
try {
311+
validate()
312+
true
313+
} catch (e: StagehandInvalidDataException) {
314+
false
315+
}
316+
317+
/**
318+
* Returns a score indicating how many valid values are contained in this object
319+
* recursively.
320+
*
321+
* Used for best match union deserialization.
322+
*/
323+
@JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1
324+
325+
override fun equals(other: Any?): Boolean {
326+
if (this === other) {
327+
return true
328+
}
329+
330+
return other is XStreamResponse && value == other.value
331+
}
332+
333+
override fun hashCode() = value.hashCode()
334+
335+
override fun toString() = value.toString()
336+
}
337+
338+
override fun equals(other: Any?): Boolean {
339+
if (this === other) {
340+
return true
341+
}
342+
343+
return other is SessionReplayParams &&
344+
id == other.id &&
345+
xStreamResponse == other.xStreamResponse &&
346+
additionalHeaders == other.additionalHeaders &&
347+
additionalQueryParams == other.additionalQueryParams
348+
}
349+
350+
override fun hashCode(): Int =
351+
Objects.hash(id, xStreamResponse, additionalHeaders, additionalQueryParams)
352+
353+
override fun toString() =
354+
"SessionReplayParams{id=$id, xStreamResponse=$xStreamResponse, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}"
355+
}

0 commit comments

Comments
 (0)