@@ -15,6 +15,7 @@ import com.browserbase.api.core.checkRequired
1515import com.browserbase.api.core.getOrThrow
1616import com.browserbase.api.core.http.Headers
1717import com.browserbase.api.core.http.QueryParams
18+ import com.browserbase.api.core.toImmutable
1819import com.browserbase.api.errors.StagehandInvalidDataException
1920import com.fasterxml.jackson.annotation.JsonAnyGetter
2021import com.fasterxml.jackson.annotation.JsonAnySetter
@@ -1806,6 +1807,7 @@ private constructor(
18061807 private val maxSteps: JsonField <Double >,
18071808 private val toolTimeout: JsonField <Double >,
18081809 private val useSearch: JsonField <Boolean >,
1810+ private val variables: JsonField <Variables >,
18091811 private val additionalProperties: MutableMap <String , JsonValue >,
18101812 ) {
18111813
@@ -1826,7 +1828,18 @@ private constructor(
18261828 @JsonProperty(" useSearch" )
18271829 @ExcludeMissing
18281830 useSearch: JsonField <Boolean > = JsonMissing .of(),
1829- ) : this (instruction, highlightCursor, maxSteps, toolTimeout, useSearch, mutableMapOf ())
1831+ @JsonProperty(" variables" )
1832+ @ExcludeMissing
1833+ variables: JsonField <Variables > = JsonMissing .of(),
1834+ ) : this (
1835+ instruction,
1836+ highlightCursor,
1837+ maxSteps,
1838+ toolTimeout,
1839+ useSearch,
1840+ variables,
1841+ mutableMapOf (),
1842+ )
18301843
18311844 /* *
18321845 * Natural language instruction for the agent
@@ -1868,6 +1881,14 @@ private constructor(
18681881 */
18691882 fun useSearch (): Optional <Boolean > = useSearch.getOptional(" useSearch" )
18701883
1884+ /* *
1885+ * Variables available to the agent via %variableName% syntax in supported tools
1886+ *
1887+ * @throws StagehandInvalidDataException if the JSON field has an unexpected type (e.g. if
1888+ * the server responded with an unexpected value).
1889+ */
1890+ fun variables (): Optional <Variables > = variables.getOptional(" variables" )
1891+
18711892 /* *
18721893 * Returns the raw JSON value of [instruction].
18731894 *
@@ -1910,6 +1931,15 @@ private constructor(
19101931 */
19111932 @JsonProperty(" useSearch" ) @ExcludeMissing fun _useSearch (): JsonField <Boolean > = useSearch
19121933
1934+ /* *
1935+ * Returns the raw JSON value of [variables].
1936+ *
1937+ * Unlike [variables], this method doesn't throw if the JSON field has an unexpected type.
1938+ */
1939+ @JsonProperty(" variables" )
1940+ @ExcludeMissing
1941+ fun _variables (): JsonField <Variables > = variables
1942+
19131943 @JsonAnySetter
19141944 private fun putAdditionalProperty (key : String , value : JsonValue ) {
19151945 additionalProperties.put(key, value)
@@ -1943,6 +1973,7 @@ private constructor(
19431973 private var maxSteps: JsonField <Double > = JsonMissing .of()
19441974 private var toolTimeout: JsonField <Double > = JsonMissing .of()
19451975 private var useSearch: JsonField <Boolean > = JsonMissing .of()
1976+ private var variables: JsonField <Variables > = JsonMissing .of()
19461977 private var additionalProperties: MutableMap <String , JsonValue > = mutableMapOf ()
19471978
19481979 @JvmSynthetic
@@ -1952,6 +1983,7 @@ private constructor(
19521983 maxSteps = executeOptions.maxSteps
19531984 toolTimeout = executeOptions.toolTimeout
19541985 useSearch = executeOptions.useSearch
1986+ variables = executeOptions.variables
19551987 additionalProperties = executeOptions.additionalProperties.toMutableMap()
19561988 }
19571989
@@ -2022,6 +2054,18 @@ private constructor(
20222054 */
20232055 fun useSearch (useSearch : JsonField <Boolean >) = apply { this .useSearch = useSearch }
20242056
2057+ /* * Variables available to the agent via %variableName% syntax in supported tools */
2058+ fun variables (variables : Variables ) = variables(JsonField .of(variables))
2059+
2060+ /* *
2061+ * Sets [Builder.variables] to an arbitrary JSON value.
2062+ *
2063+ * You should usually call [Builder.variables] with a well-typed [Variables] value
2064+ * instead. This method is primarily for setting the field to an undocumented or not yet
2065+ * supported value.
2066+ */
2067+ fun variables (variables : JsonField <Variables >) = apply { this .variables = variables }
2068+
20252069 fun additionalProperties (additionalProperties : Map <String , JsonValue >) = apply {
20262070 this .additionalProperties.clear()
20272071 putAllAdditionalProperties(additionalProperties)
@@ -2060,6 +2104,7 @@ private constructor(
20602104 maxSteps,
20612105 toolTimeout,
20622106 useSearch,
2107+ variables,
20632108 additionalProperties.toMutableMap(),
20642109 )
20652110 }
@@ -2085,6 +2130,7 @@ private constructor(
20852130 maxSteps()
20862131 toolTimeout()
20872132 useSearch()
2133+ variables().ifPresent { it.validate() }
20882134 validated = true
20892135 }
20902136
@@ -2108,7 +2154,121 @@ private constructor(
21082154 (if (highlightCursor.asKnown().isPresent) 1 else 0 ) +
21092155 (if (maxSteps.asKnown().isPresent) 1 else 0 ) +
21102156 (if (toolTimeout.asKnown().isPresent) 1 else 0 ) +
2111- (if (useSearch.asKnown().isPresent) 1 else 0 )
2157+ (if (useSearch.asKnown().isPresent) 1 else 0 ) +
2158+ (variables.asKnown().getOrNull()?.validity() ? : 0 )
2159+
2160+ /* * Variables available to the agent via %variableName% syntax in supported tools */
2161+ class Variables
2162+ @JsonCreator
2163+ private constructor (
2164+ @com.fasterxml.jackson.annotation.JsonValue
2165+ private val additionalProperties: Map <String , JsonValue >
2166+ ) {
2167+
2168+ @JsonAnyGetter
2169+ @ExcludeMissing
2170+ fun _additionalProperties (): Map <String , JsonValue > = additionalProperties
2171+
2172+ fun toBuilder () = Builder ().from(this )
2173+
2174+ companion object {
2175+
2176+ /* * Returns a mutable builder for constructing an instance of [Variables]. */
2177+ @JvmStatic fun builder () = Builder ()
2178+ }
2179+
2180+ /* * A builder for [Variables]. */
2181+ class Builder internal constructor() {
2182+
2183+ private var additionalProperties: MutableMap <String , JsonValue > = mutableMapOf ()
2184+
2185+ @JvmSynthetic
2186+ internal fun from (variables : Variables ) = apply {
2187+ additionalProperties = variables.additionalProperties.toMutableMap()
2188+ }
2189+
2190+ fun additionalProperties (additionalProperties : Map <String , JsonValue >) = apply {
2191+ this .additionalProperties.clear()
2192+ putAllAdditionalProperties(additionalProperties)
2193+ }
2194+
2195+ fun putAdditionalProperty (key : String , value : JsonValue ) = apply {
2196+ additionalProperties.put(key, value)
2197+ }
2198+
2199+ fun putAllAdditionalProperties (additionalProperties : Map <String , JsonValue >) =
2200+ apply {
2201+ this .additionalProperties.putAll(additionalProperties)
2202+ }
2203+
2204+ fun removeAdditionalProperty (key : String ) = apply {
2205+ additionalProperties.remove(key)
2206+ }
2207+
2208+ fun removeAllAdditionalProperties (keys : Set <String >) = apply {
2209+ keys.forEach(::removeAdditionalProperty)
2210+ }
2211+
2212+ /* *
2213+ * Returns an immutable instance of [Variables].
2214+ *
2215+ * Further updates to this [Builder] will not mutate the returned instance.
2216+ */
2217+ fun build (): Variables = Variables (additionalProperties.toImmutable())
2218+ }
2219+
2220+ private var validated: Boolean = false
2221+
2222+ /* *
2223+ * Validates that the types of all values in this object match their expected types
2224+ * recursively.
2225+ *
2226+ * This method is _not_ forwards compatible with new types from the API for existing
2227+ * fields.
2228+ *
2229+ * @throws StagehandInvalidDataException if any value type in this object doesn't match
2230+ * its expected type.
2231+ */
2232+ fun validate (): Variables = apply {
2233+ if (validated) {
2234+ return @apply
2235+ }
2236+
2237+ validated = true
2238+ }
2239+
2240+ fun isValid (): Boolean =
2241+ try {
2242+ validate()
2243+ true
2244+ } catch (e: StagehandInvalidDataException ) {
2245+ false
2246+ }
2247+
2248+ /* *
2249+ * Returns a score indicating how many valid values are contained in this object
2250+ * recursively.
2251+ *
2252+ * Used for best match union deserialization.
2253+ */
2254+ @JvmSynthetic
2255+ internal fun validity (): Int =
2256+ additionalProperties.count { (_, value) -> ! value.isNull() && ! value.isMissing() }
2257+
2258+ override fun equals (other : Any? ): Boolean {
2259+ if (this == = other) {
2260+ return true
2261+ }
2262+
2263+ return other is Variables && additionalProperties == other.additionalProperties
2264+ }
2265+
2266+ private val hashCode: Int by lazy { Objects .hash(additionalProperties) }
2267+
2268+ override fun hashCode (): Int = hashCode
2269+
2270+ override fun toString () = " Variables{additionalProperties=$additionalProperties }"
2271+ }
21122272
21132273 override fun equals (other : Any? ): Boolean {
21142274 if (this == = other) {
@@ -2121,6 +2281,7 @@ private constructor(
21212281 maxSteps == other.maxSteps &&
21222282 toolTimeout == other.toolTimeout &&
21232283 useSearch == other.useSearch &&
2284+ variables == other.variables &&
21242285 additionalProperties == other.additionalProperties
21252286 }
21262287
@@ -2131,14 +2292,15 @@ private constructor(
21312292 maxSteps,
21322293 toolTimeout,
21332294 useSearch,
2295+ variables,
21342296 additionalProperties,
21352297 )
21362298 }
21372299
21382300 override fun hashCode (): Int = hashCode
21392301
21402302 override fun toString () =
2141- " ExecuteOptions{instruction=$instruction , highlightCursor=$highlightCursor , maxSteps=$maxSteps , toolTimeout=$toolTimeout , useSearch=$useSearch , additionalProperties=$additionalProperties }"
2303+ " ExecuteOptions{instruction=$instruction , highlightCursor=$highlightCursor , maxSteps=$maxSteps , toolTimeout=$toolTimeout , useSearch=$useSearch , variables= $variables , additionalProperties=$additionalProperties }"
21422304 }
21432305
21442306 /* * Whether to stream the response via SSE */
0 commit comments