Skip to content

Commit a0a2a81

Browse files
author
stlc-bot
committed
Add immutable user_metadata tags to v2 parse jobs (#21177)
Stainless-Generated-From: 5e982f7908e22cc6dd5ee4c2957bc2305a7fafd1
1 parent a3add10 commit a0a2a81

12 files changed

Lines changed: 834 additions & 9 deletions

File tree

‎llama-cloud-core/src/main/kotlin/com/llamacloud_prod/api/models/parsing/ParsingCreateParams.kt‎

Lines changed: 208 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,16 @@ private constructor(
212212
*/
213213
fun sourceUrl(): Optional<String> = body.sourceUrl()
214214

215+
/**
216+
* Arbitrary key/value tags to attach to this job. Returned when retrieving the job. Not
217+
* searchable. Limits apply to the number of entries and the length of keys and values;
218+
* oversized metadata is rejected.
219+
*
220+
* @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the
221+
* server responded with an unexpected value).
222+
*/
223+
fun userMetadata(): Optional<UserMetadata> = body.userMetadata()
224+
215225
/**
216226
* Webhook endpoints for job status notifications. Multiple webhooks can be configured for
217227
* different events or services
@@ -328,6 +338,13 @@ private constructor(
328338
*/
329339
fun _sourceUrl(): JsonField<String> = body._sourceUrl()
330340

341+
/**
342+
* Returns the raw JSON value of [userMetadata].
343+
*
344+
* Unlike [userMetadata], this method doesn't throw if the JSON field has an unexpected type.
345+
*/
346+
fun _userMetadata(): JsonField<UserMetadata> = body._userMetadata()
347+
331348
/**
332349
* Returns the raw JSON value of [webhookConfigurations].
333350
*
@@ -693,6 +710,28 @@ private constructor(
693710
*/
694711
fun sourceUrl(sourceUrl: JsonField<String>) = apply { body.sourceUrl(sourceUrl) }
695712

713+
/**
714+
* Arbitrary key/value tags to attach to this job. Returned when retrieving the job. Not
715+
* searchable. Limits apply to the number of entries and the length of keys and values;
716+
* oversized metadata is rejected.
717+
*/
718+
fun userMetadata(userMetadata: UserMetadata?) = apply { body.userMetadata(userMetadata) }
719+
720+
/** Alias for calling [Builder.userMetadata] with `userMetadata.orElse(null)`. */
721+
fun userMetadata(userMetadata: Optional<UserMetadata>) =
722+
userMetadata(userMetadata.getOrNull())
723+
724+
/**
725+
* Sets [Builder.userMetadata] to an arbitrary JSON value.
726+
*
727+
* You should usually call [Builder.userMetadata] with a well-typed [UserMetadata] value
728+
* instead. This method is primarily for setting the field to an undocumented or not yet
729+
* supported value.
730+
*/
731+
fun userMetadata(userMetadata: JsonField<UserMetadata>) = apply {
732+
body.userMetadata(userMetadata)
733+
}
734+
696735
/**
697736
* Webhook endpoints for job status notifications. Multiple webhooks can be configured for
698737
* different events or services
@@ -900,6 +939,7 @@ private constructor(
900939
private val processingControl: JsonField<ProcessingControl>,
901940
private val processingOptions: JsonField<ProcessingOptions>,
902941
private val sourceUrl: JsonField<String>,
942+
private val userMetadata: JsonField<UserMetadata>,
903943
private val webhookConfigurations: JsonField<List<WebhookConfiguration>>,
904944
private val additionalProperties: MutableMap<String, JsonValue>,
905945
) {
@@ -946,6 +986,9 @@ private constructor(
946986
@JsonProperty("source_url")
947987
@ExcludeMissing
948988
sourceUrl: JsonField<String> = JsonMissing.of(),
989+
@JsonProperty("user_metadata")
990+
@ExcludeMissing
991+
userMetadata: JsonField<UserMetadata> = JsonMissing.of(),
949992
@JsonProperty("webhook_configurations")
950993
@ExcludeMissing
951994
webhookConfigurations: JsonField<List<WebhookConfiguration>> = JsonMissing.of(),
@@ -966,6 +1009,7 @@ private constructor(
9661009
processingControl,
9671010
processingOptions,
9681011
sourceUrl,
1012+
userMetadata,
9691013
webhookConfigurations,
9701014
mutableMapOf(),
9711015
)
@@ -1125,6 +1169,16 @@ private constructor(
11251169
*/
11261170
fun sourceUrl(): Optional<String> = sourceUrl.getOptional("source_url")
11271171

1172+
/**
1173+
* Arbitrary key/value tags to attach to this job. Returned when retrieving the job. Not
1174+
* searchable. Limits apply to the number of entries and the length of keys and values;
1175+
* oversized metadata is rejected.
1176+
*
1177+
* @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if
1178+
* the server responded with an unexpected value).
1179+
*/
1180+
fun userMetadata(): Optional<UserMetadata> = userMetadata.getOptional("user_metadata")
1181+
11281182
/**
11291183
* Webhook endpoints for job status notifications. Multiple webhooks can be configured for
11301184
* different events or services
@@ -1265,6 +1319,16 @@ private constructor(
12651319
*/
12661320
@JsonProperty("source_url") @ExcludeMissing fun _sourceUrl(): JsonField<String> = sourceUrl
12671321

1322+
/**
1323+
* Returns the raw JSON value of [userMetadata].
1324+
*
1325+
* Unlike [userMetadata], this method doesn't throw if the JSON field has an unexpected
1326+
* type.
1327+
*/
1328+
@JsonProperty("user_metadata")
1329+
@ExcludeMissing
1330+
fun _userMetadata(): JsonField<UserMetadata> = userMetadata
1331+
12681332
/**
12691333
* Returns the raw JSON value of [webhookConfigurations].
12701334
*
@@ -1320,6 +1384,7 @@ private constructor(
13201384
private var processingControl: JsonField<ProcessingControl> = JsonMissing.of()
13211385
private var processingOptions: JsonField<ProcessingOptions> = JsonMissing.of()
13221386
private var sourceUrl: JsonField<String> = JsonMissing.of()
1387+
private var userMetadata: JsonField<UserMetadata> = JsonMissing.of()
13231388
private var webhookConfigurations: JsonField<MutableList<WebhookConfiguration>>? = null
13241389
private var additionalProperties: MutableMap<String, JsonValue> = mutableMapOf()
13251390

@@ -1341,6 +1406,7 @@ private constructor(
13411406
processingControl = body.processingControl
13421407
processingOptions = body.processingOptions
13431408
sourceUrl = body.sourceUrl
1409+
userMetadata = body.userMetadata
13441410
webhookConfigurations = body.webhookConfigurations.map { it.toMutableList() }
13451411
additionalProperties = body.additionalProperties.toMutableMap()
13461412
}
@@ -1642,6 +1708,29 @@ private constructor(
16421708
*/
16431709
fun sourceUrl(sourceUrl: JsonField<String>) = apply { this.sourceUrl = sourceUrl }
16441710

1711+
/**
1712+
* Arbitrary key/value tags to attach to this job. Returned when retrieving the job. Not
1713+
* searchable. Limits apply to the number of entries and the length of keys and values;
1714+
* oversized metadata is rejected.
1715+
*/
1716+
fun userMetadata(userMetadata: UserMetadata?) =
1717+
userMetadata(JsonField.ofNullable(userMetadata))
1718+
1719+
/** Alias for calling [Builder.userMetadata] with `userMetadata.orElse(null)`. */
1720+
fun userMetadata(userMetadata: Optional<UserMetadata>) =
1721+
userMetadata(userMetadata.getOrNull())
1722+
1723+
/**
1724+
* Sets [Builder.userMetadata] to an arbitrary JSON value.
1725+
*
1726+
* You should usually call [Builder.userMetadata] with a well-typed [UserMetadata] value
1727+
* instead. This method is primarily for setting the field to an undocumented or not yet
1728+
* supported value.
1729+
*/
1730+
fun userMetadata(userMetadata: JsonField<UserMetadata>) = apply {
1731+
this.userMetadata = userMetadata
1732+
}
1733+
16451734
/**
16461735
* Webhook endpoints for job status notifications. Multiple webhooks can be configured
16471736
* for different events or services
@@ -1724,6 +1813,7 @@ private constructor(
17241813
processingControl,
17251814
processingOptions,
17261815
sourceUrl,
1816+
userMetadata,
17271817
(webhookConfigurations ?: JsonMissing.of()).map { it.toImmutable() },
17281818
additionalProperties.toMutableMap(),
17291819
)
@@ -1760,6 +1850,7 @@ private constructor(
17601850
processingControl().ifPresent { it.validate() }
17611851
processingOptions().ifPresent { it.validate() }
17621852
sourceUrl()
1853+
userMetadata().ifPresent { it.validate() }
17631854
webhookConfigurations().ifPresent { it.forEach { it.validate() } }
17641855
validated = true
17651856
}
@@ -1795,6 +1886,7 @@ private constructor(
17951886
(processingControl.asKnown().getOrNull()?.validity() ?: 0) +
17961887
(processingOptions.asKnown().getOrNull()?.validity() ?: 0) +
17971888
(if (sourceUrl.asKnown().isPresent) 1 else 0) +
1889+
(userMetadata.asKnown().getOrNull()?.validity() ?: 0) +
17981890
(webhookConfigurations.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0)
17991891

18001892
override fun equals(other: Any?): Boolean {
@@ -1819,6 +1911,7 @@ private constructor(
18191911
processingControl == other.processingControl &&
18201912
processingOptions == other.processingOptions &&
18211913
sourceUrl == other.sourceUrl &&
1914+
userMetadata == other.userMetadata &&
18221915
webhookConfigurations == other.webhookConfigurations &&
18231916
additionalProperties == other.additionalProperties
18241917
}
@@ -1841,6 +1934,7 @@ private constructor(
18411934
processingControl,
18421935
processingOptions,
18431936
sourceUrl,
1937+
userMetadata,
18441938
webhookConfigurations,
18451939
additionalProperties,
18461940
)
@@ -1849,7 +1943,7 @@ private constructor(
18491943
override fun hashCode(): Int = hashCode
18501944

18511945
override fun toString() =
1852-
"Body{tier=$tier, version=$version, agenticOptions=$agenticOptions, clientName=$clientName, configurationId=$configurationId, cropBox=$cropBox, disableCache=$disableCache, fastOptions=$fastOptions, fileId=$fileId, httpProxy=$httpProxy, inputOptions=$inputOptions, outputOptions=$outputOptions, pageRanges=$pageRanges, processingControl=$processingControl, processingOptions=$processingOptions, sourceUrl=$sourceUrl, webhookConfigurations=$webhookConfigurations, additionalProperties=$additionalProperties}"
1946+
"Body{tier=$tier, version=$version, agenticOptions=$agenticOptions, clientName=$clientName, configurationId=$configurationId, cropBox=$cropBox, disableCache=$disableCache, fastOptions=$fastOptions, fileId=$fileId, httpProxy=$httpProxy, inputOptions=$inputOptions, outputOptions=$outputOptions, pageRanges=$pageRanges, processingControl=$processingControl, processingOptions=$processingOptions, sourceUrl=$sourceUrl, userMetadata=$userMetadata, webhookConfigurations=$webhookConfigurations, additionalProperties=$additionalProperties}"
18531947
}
18541948

18551949
/**
@@ -18743,6 +18837,119 @@ private constructor(
1874318837
"ProcessingOptions{aggressiveTableExtraction=$aggressiveTableExtraction, autoModeConfiguration=$autoModeConfiguration, costOptimizer=$costOptimizer, disableHeuristics=$disableHeuristics, ignore=$ignore, ocrParameters=$ocrParameters, specializedChartParsing=$specializedChartParsing, additionalProperties=$additionalProperties}"
1874418838
}
1874518839

18840+
/**
18841+
* Arbitrary key/value tags to attach to this job. Returned when retrieving the job. Not
18842+
* searchable. Limits apply to the number of entries and the length of keys and values;
18843+
* oversized metadata is rejected.
18844+
*/
18845+
class UserMetadata
18846+
@JsonCreator
18847+
private constructor(
18848+
@com.fasterxml.jackson.annotation.JsonValue
18849+
private val additionalProperties: Map<String, JsonValue>
18850+
) {
18851+
18852+
@JsonAnyGetter
18853+
@ExcludeMissing
18854+
fun _additionalProperties(): Map<String, JsonValue> = additionalProperties
18855+
18856+
fun toBuilder() = Builder().from(this)
18857+
18858+
companion object {
18859+
18860+
/** Returns a mutable builder for constructing an instance of [UserMetadata]. */
18861+
@JvmStatic fun builder() = Builder()
18862+
}
18863+
18864+
/** A builder for [UserMetadata]. */
18865+
class Builder internal constructor() {
18866+
18867+
private var additionalProperties: MutableMap<String, JsonValue> = mutableMapOf()
18868+
18869+
@JvmSynthetic
18870+
internal fun from(userMetadata: UserMetadata) = apply {
18871+
additionalProperties = userMetadata.additionalProperties.toMutableMap()
18872+
}
18873+
18874+
fun additionalProperties(additionalProperties: Map<String, JsonValue>) = apply {
18875+
this.additionalProperties.clear()
18876+
putAllAdditionalProperties(additionalProperties)
18877+
}
18878+
18879+
fun putAdditionalProperty(key: String, value: JsonValue) = apply {
18880+
additionalProperties.put(key, value)
18881+
}
18882+
18883+
fun putAllAdditionalProperties(additionalProperties: Map<String, JsonValue>) = apply {
18884+
this.additionalProperties.putAll(additionalProperties)
18885+
}
18886+
18887+
fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) }
18888+
18889+
fun removeAllAdditionalProperties(keys: Set<String>) = apply {
18890+
keys.forEach(::removeAdditionalProperty)
18891+
}
18892+
18893+
/**
18894+
* Returns an immutable instance of [UserMetadata].
18895+
*
18896+
* Further updates to this [Builder] will not mutate the returned instance.
18897+
*/
18898+
fun build(): UserMetadata = UserMetadata(additionalProperties.toImmutable())
18899+
}
18900+
18901+
private var validated: Boolean = false
18902+
18903+
/**
18904+
* Validates that the types of all values in this object match their expected types
18905+
* recursively.
18906+
*
18907+
* This method is _not_ forwards compatible with new types from the API for existing fields.
18908+
*
18909+
* @throws LlamaCloudInvalidDataException if any value type in this object doesn't match its
18910+
* expected type.
18911+
*/
18912+
fun validate(): UserMetadata = apply {
18913+
if (validated) {
18914+
return@apply
18915+
}
18916+
18917+
validated = true
18918+
}
18919+
18920+
fun isValid(): Boolean =
18921+
try {
18922+
validate()
18923+
true
18924+
} catch (e: LlamaCloudInvalidDataException) {
18925+
false
18926+
}
18927+
18928+
/**
18929+
* Returns a score indicating how many valid values are contained in this object
18930+
* recursively.
18931+
*
18932+
* Used for best match union deserialization.
18933+
*/
18934+
@JvmSynthetic
18935+
internal fun validity(): Int =
18936+
additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() }
18937+
18938+
override fun equals(other: Any?): Boolean {
18939+
if (this === other) {
18940+
return true
18941+
}
18942+
18943+
return other is UserMetadata && additionalProperties == other.additionalProperties
18944+
}
18945+
18946+
private val hashCode: Int by lazy { Objects.hash(additionalProperties) }
18947+
18948+
override fun hashCode(): Int = hashCode
18949+
18950+
override fun toString() = "UserMetadata{additionalProperties=$additionalProperties}"
18951+
}
18952+
1874618953
/**
1874718954
* Webhook configuration for receiving parsing job notifications.
1874818955
*

0 commit comments

Comments
 (0)