mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2026-08-09 08:04:45 +00:00
feat: add typed build parameters and shared DVM tag infrastructure
Add shared tag classes (InputTag, OutputTag) and TagArrayBuilder extensions (inputUrl, inputText, inputEvent, inputJob, inputPrompt, output, param) for all DVM kinds to reuse. Update all 17 request event build() methods with typed parameters matching their spec: - 5000: inputUrl, outputMimeType, range, alignment - 5001: eventIds, length, outputMimeType - 5002: eventIds, language - 5050: prompt, model, maxTokens, temperature, topK, topP, frequencyPenalty - 5100: prompt, sourceImageUrl, model, lora, ratio, size, negativePrompt - 5200: videoUrl, outputMimeType, range - 5201: videoUrl, language, subtitle, range, outputFormat - 5202: imageUrl - 5250: text, language - 5302: searchQuery, users, since, until, maxResults - 5303: searchQuery, maxResults - 5400: inputs, relays, groups, filterJson - 5500: fileUrl - 5900: eventId - 5901: text - 5905: eventJson, relays - 5970: eventJson, pow https://claude.ai/code/session_017aamEDeRtQ2H9u5U9B5F1C
This commit is contained in:
+12
@@ -26,6 +26,8 @@ import com.vitorpamplona.quartz.nip01Core.core.HexKey
|
||||
import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
|
||||
import com.vitorpamplona.quartz.nip01Core.signers.eventTemplate
|
||||
import com.vitorpamplona.quartz.nip31Alts.alt
|
||||
import com.vitorpamplona.quartz.nip90Dvms.tags.inputText
|
||||
import com.vitorpamplona.quartz.nip90Dvms.tags.param
|
||||
import com.vitorpamplona.quartz.utils.TimeUtils
|
||||
|
||||
@Immutable
|
||||
@@ -42,10 +44,20 @@ class NIP90ContentSearchRequestEvent(
|
||||
const val ALT = "NIP90 Content Search request"
|
||||
|
||||
fun build(
|
||||
searchQuery: String,
|
||||
users: String? = null,
|
||||
since: Long? = null,
|
||||
until: Long? = null,
|
||||
maxResults: Int? = null,
|
||||
createdAt: Long = TimeUtils.now(),
|
||||
initializer: TagArrayBuilder<NIP90ContentSearchRequestEvent>.() -> Unit = {},
|
||||
) = eventTemplate(KIND, "", createdAt) {
|
||||
alt(ALT)
|
||||
inputText(searchQuery)
|
||||
users?.let { param("users", it) }
|
||||
since?.let { param("since", it.toString()) }
|
||||
until?.let { param("until", it.toString()) }
|
||||
maxResults?.let { param("max_results", it.toString()) }
|
||||
initializer()
|
||||
}
|
||||
}
|
||||
|
||||
+10
-1
@@ -26,6 +26,8 @@ import com.vitorpamplona.quartz.nip01Core.core.HexKey
|
||||
import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
|
||||
import com.vitorpamplona.quartz.nip01Core.signers.eventTemplate
|
||||
import com.vitorpamplona.quartz.nip31Alts.alt
|
||||
import com.vitorpamplona.quartz.nip90Dvms.tags.inputText
|
||||
import com.vitorpamplona.quartz.nip90Dvms.tags.param
|
||||
import com.vitorpamplona.quartz.utils.TimeUtils
|
||||
|
||||
@Immutable
|
||||
@@ -42,10 +44,17 @@ class NIP90EventCountRequestEvent(
|
||||
const val ALT = "NIP90 Event Count request"
|
||||
|
||||
fun build(
|
||||
inputs: List<String> = emptyList(),
|
||||
relays: List<String>,
|
||||
groups: List<String> = emptyList(),
|
||||
filterJson: String = "",
|
||||
createdAt: Long = TimeUtils.now(),
|
||||
initializer: TagArrayBuilder<NIP90EventCountRequestEvent>.() -> Unit = {},
|
||||
) = eventTemplate(KIND, "", createdAt) {
|
||||
) = eventTemplate(KIND, filterJson, createdAt) {
|
||||
alt(ALT)
|
||||
inputs.forEach { inputText(it) }
|
||||
relays.forEach { param("relay", it) }
|
||||
groups.forEach { param("group", it) }
|
||||
initializer()
|
||||
}
|
||||
}
|
||||
|
||||
+6
@@ -26,6 +26,8 @@ import com.vitorpamplona.quartz.nip01Core.core.HexKey
|
||||
import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
|
||||
import com.vitorpamplona.quartz.nip01Core.signers.eventTemplate
|
||||
import com.vitorpamplona.quartz.nip31Alts.alt
|
||||
import com.vitorpamplona.quartz.nip90Dvms.tags.inputText
|
||||
import com.vitorpamplona.quartz.nip90Dvms.tags.param
|
||||
import com.vitorpamplona.quartz.utils.TimeUtils
|
||||
|
||||
@Immutable
|
||||
@@ -42,10 +44,14 @@ class NIP90EventPowDelegationRequestEvent(
|
||||
const val ALT = "NIP90 Event PoW Delegation request"
|
||||
|
||||
fun build(
|
||||
eventJson: String,
|
||||
pow: Int,
|
||||
createdAt: Long = TimeUtils.now(),
|
||||
initializer: TagArrayBuilder<NIP90EventPowDelegationRequestEvent>.() -> Unit = {},
|
||||
) = eventTemplate(KIND, "", createdAt) {
|
||||
alt(ALT)
|
||||
inputText(eventJson)
|
||||
param("pow", pow.toString())
|
||||
initializer()
|
||||
}
|
||||
}
|
||||
|
||||
+8
@@ -26,6 +26,8 @@ import com.vitorpamplona.quartz.nip01Core.core.HexKey
|
||||
import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
|
||||
import com.vitorpamplona.quartz.nip01Core.signers.eventTemplate
|
||||
import com.vitorpamplona.quartz.nip31Alts.alt
|
||||
import com.vitorpamplona.quartz.nip90Dvms.tags.inputText
|
||||
import com.vitorpamplona.quartz.nip90Dvms.tags.param
|
||||
import com.vitorpamplona.quartz.utils.TimeUtils
|
||||
|
||||
@Immutable
|
||||
@@ -42,10 +44,16 @@ class NIP90EventPublishScheduleRequestEvent(
|
||||
const val ALT = "NIP90 Event Publish Schedule request"
|
||||
|
||||
fun build(
|
||||
eventJson: String,
|
||||
relays: List<String> = emptyList(),
|
||||
createdAt: Long = TimeUtils.now(),
|
||||
initializer: TagArrayBuilder<NIP90EventPublishScheduleRequestEvent>.() -> Unit = {},
|
||||
) = eventTemplate(KIND, "", createdAt) {
|
||||
alt(ALT)
|
||||
inputText(eventJson)
|
||||
if (relays.isNotEmpty()) {
|
||||
param("relays", *relays.toTypedArray())
|
||||
}
|
||||
initializer()
|
||||
}
|
||||
}
|
||||
|
||||
+3
@@ -26,6 +26,7 @@ import com.vitorpamplona.quartz.nip01Core.core.HexKey
|
||||
import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
|
||||
import com.vitorpamplona.quartz.nip01Core.signers.eventTemplate
|
||||
import com.vitorpamplona.quartz.nip31Alts.alt
|
||||
import com.vitorpamplona.quartz.nip90Dvms.tags.inputEvent
|
||||
import com.vitorpamplona.quartz.utils.TimeUtils
|
||||
|
||||
@Immutable
|
||||
@@ -42,10 +43,12 @@ class NIP90EventTimestampingRequestEvent(
|
||||
const val ALT = "NIP90 Event Timestamping request"
|
||||
|
||||
fun build(
|
||||
eventId: HexKey,
|
||||
createdAt: Long = TimeUtils.now(),
|
||||
initializer: TagArrayBuilder<NIP90EventTimestampingRequestEvent>.() -> Unit = {},
|
||||
) = eventTemplate(KIND, "", createdAt) {
|
||||
alt(ALT)
|
||||
inputEvent(eventId)
|
||||
initializer()
|
||||
}
|
||||
}
|
||||
|
||||
+17
@@ -26,6 +26,9 @@ import com.vitorpamplona.quartz.nip01Core.core.HexKey
|
||||
import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
|
||||
import com.vitorpamplona.quartz.nip01Core.signers.eventTemplate
|
||||
import com.vitorpamplona.quartz.nip31Alts.alt
|
||||
import com.vitorpamplona.quartz.nip90Dvms.tags.inputText
|
||||
import com.vitorpamplona.quartz.nip90Dvms.tags.inputUrl
|
||||
import com.vitorpamplona.quartz.nip90Dvms.tags.param
|
||||
import com.vitorpamplona.quartz.utils.TimeUtils
|
||||
|
||||
@Immutable
|
||||
@@ -42,10 +45,24 @@ class NIP90ImageGenerationRequestEvent(
|
||||
const val ALT = "NIP90 Image Generation request"
|
||||
|
||||
fun build(
|
||||
prompt: String,
|
||||
sourceImageUrl: String? = null,
|
||||
model: String? = null,
|
||||
lora: String? = null,
|
||||
ratio: String? = null,
|
||||
size: String? = null,
|
||||
negativePrompt: String? = null,
|
||||
createdAt: Long = TimeUtils.now(),
|
||||
initializer: TagArrayBuilder<NIP90ImageGenerationRequestEvent>.() -> Unit = {},
|
||||
) = eventTemplate(KIND, "", createdAt) {
|
||||
alt(ALT)
|
||||
sourceImageUrl?.let { inputUrl(it) }
|
||||
inputText(prompt)
|
||||
model?.let { param("model", it) }
|
||||
lora?.let { param("lora", it) }
|
||||
size?.let { param("size", it) }
|
||||
ratio?.let { param("ratio", it) }
|
||||
negativePrompt?.let { param("negative_prompt", it) }
|
||||
initializer()
|
||||
}
|
||||
}
|
||||
|
||||
+3
@@ -26,6 +26,7 @@ import com.vitorpamplona.quartz.nip01Core.core.HexKey
|
||||
import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
|
||||
import com.vitorpamplona.quartz.nip01Core.signers.eventTemplate
|
||||
import com.vitorpamplona.quartz.nip31Alts.alt
|
||||
import com.vitorpamplona.quartz.nip90Dvms.tags.inputUrl
|
||||
import com.vitorpamplona.quartz.utils.TimeUtils
|
||||
|
||||
@Immutable
|
||||
@@ -42,10 +43,12 @@ class NIP90ImageToVideoRequestEvent(
|
||||
const val ALT = "NIP90 Image-to-Video request"
|
||||
|
||||
fun build(
|
||||
imageUrl: String,
|
||||
createdAt: Long = TimeUtils.now(),
|
||||
initializer: TagArrayBuilder<NIP90ImageToVideoRequestEvent>.() -> Unit = {},
|
||||
) = eventTemplate(KIND, "", createdAt) {
|
||||
alt(ALT)
|
||||
inputUrl(imageUrl)
|
||||
initializer()
|
||||
}
|
||||
}
|
||||
|
||||
+3
@@ -26,6 +26,7 @@ import com.vitorpamplona.quartz.nip01Core.core.HexKey
|
||||
import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
|
||||
import com.vitorpamplona.quartz.nip01Core.signers.eventTemplate
|
||||
import com.vitorpamplona.quartz.nip31Alts.alt
|
||||
import com.vitorpamplona.quartz.nip90Dvms.tags.inputUrl
|
||||
import com.vitorpamplona.quartz.utils.TimeUtils
|
||||
|
||||
@Immutable
|
||||
@@ -42,10 +43,12 @@ class NIP90MalwareScanRequestEvent(
|
||||
const val ALT = "NIP90 Malware Scan request"
|
||||
|
||||
fun build(
|
||||
fileUrl: String,
|
||||
createdAt: Long = TimeUtils.now(),
|
||||
initializer: TagArrayBuilder<NIP90MalwareScanRequestEvent>.() -> Unit = {},
|
||||
) = eventTemplate(KIND, "", createdAt) {
|
||||
alt(ALT)
|
||||
inputUrl(fileUrl)
|
||||
initializer()
|
||||
}
|
||||
}
|
||||
|
||||
+4
@@ -26,6 +26,7 @@ import com.vitorpamplona.quartz.nip01Core.core.HexKey
|
||||
import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
|
||||
import com.vitorpamplona.quartz.nip01Core.signers.eventTemplate
|
||||
import com.vitorpamplona.quartz.nip31Alts.alt
|
||||
import com.vitorpamplona.quartz.nip90Dvms.tags.inputText
|
||||
import com.vitorpamplona.quartz.utils.TimeUtils
|
||||
|
||||
@Immutable
|
||||
@@ -40,12 +41,15 @@ class NIP90OpReturnRequestEvent(
|
||||
companion object {
|
||||
const val KIND = 5901
|
||||
const val ALT = "NIP90 OP_RETURN Creation request"
|
||||
const val MAX_OP_RETURN_BYTES = 80
|
||||
|
||||
fun build(
|
||||
text: String,
|
||||
createdAt: Long = TimeUtils.now(),
|
||||
initializer: TagArrayBuilder<NIP90OpReturnRequestEvent>.() -> Unit = {},
|
||||
) = eventTemplate(KIND, "", createdAt) {
|
||||
alt(ALT)
|
||||
inputText(text)
|
||||
initializer()
|
||||
}
|
||||
}
|
||||
|
||||
+6
@@ -26,6 +26,8 @@ import com.vitorpamplona.quartz.nip01Core.core.HexKey
|
||||
import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
|
||||
import com.vitorpamplona.quartz.nip01Core.signers.eventTemplate
|
||||
import com.vitorpamplona.quartz.nip31Alts.alt
|
||||
import com.vitorpamplona.quartz.nip90Dvms.tags.inputText
|
||||
import com.vitorpamplona.quartz.nip90Dvms.tags.param
|
||||
import com.vitorpamplona.quartz.utils.TimeUtils
|
||||
|
||||
@Immutable
|
||||
@@ -42,10 +44,14 @@ class NIP90PeopleSearchRequestEvent(
|
||||
const val ALT = "NIP90 People Search request"
|
||||
|
||||
fun build(
|
||||
searchQuery: String,
|
||||
maxResults: Int? = null,
|
||||
createdAt: Long = TimeUtils.now(),
|
||||
initializer: TagArrayBuilder<NIP90PeopleSearchRequestEvent>.() -> Unit = {},
|
||||
) = eventTemplate(KIND, "", createdAt) {
|
||||
alt(ALT)
|
||||
inputText(searchQuery)
|
||||
maxResults?.let { param("max_results", it.toString()) }
|
||||
initializer()
|
||||
}
|
||||
}
|
||||
|
||||
+9
@@ -26,6 +26,9 @@ import com.vitorpamplona.quartz.nip01Core.core.HexKey
|
||||
import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
|
||||
import com.vitorpamplona.quartz.nip01Core.signers.eventTemplate
|
||||
import com.vitorpamplona.quartz.nip31Alts.alt
|
||||
import com.vitorpamplona.quartz.nip90Dvms.tags.inputEvent
|
||||
import com.vitorpamplona.quartz.nip90Dvms.tags.output
|
||||
import com.vitorpamplona.quartz.nip90Dvms.tags.param
|
||||
import com.vitorpamplona.quartz.utils.TimeUtils
|
||||
|
||||
@Immutable
|
||||
@@ -42,10 +45,16 @@ class NIP90SummarizationRequestEvent(
|
||||
const val ALT = "NIP90 Summarization request"
|
||||
|
||||
fun build(
|
||||
eventIds: List<HexKey>,
|
||||
length: String? = null,
|
||||
outputMimeType: String? = null,
|
||||
createdAt: Long = TimeUtils.now(),
|
||||
initializer: TagArrayBuilder<NIP90SummarizationRequestEvent>.() -> Unit = {},
|
||||
) = eventTemplate(KIND, "", createdAt) {
|
||||
alt(ALT)
|
||||
eventIds.forEach { inputEvent(it) }
|
||||
length?.let { param("length", it) }
|
||||
outputMimeType?.let { output(it) }
|
||||
initializer()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (c) 2025 Vitor Pamplona
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to use,
|
||||
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
|
||||
* Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
||||
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
package com.vitorpamplona.quartz.nip90Dvms.tags
|
||||
|
||||
import androidx.compose.runtime.Stable
|
||||
import com.vitorpamplona.quartz.nip01Core.core.has
|
||||
import com.vitorpamplona.quartz.utils.ensure
|
||||
|
||||
@Stable
|
||||
class InputTag(
|
||||
val value: String,
|
||||
val type: String,
|
||||
val relay: String? = null,
|
||||
val marker: String? = null,
|
||||
) {
|
||||
companion object {
|
||||
const val TAG_NAME = "i"
|
||||
|
||||
fun parse(tag: Array<String>): InputTag? {
|
||||
ensure(tag.has(2)) { return null }
|
||||
ensure(tag[0] == TAG_NAME) { return null }
|
||||
ensure(tag[1].isNotEmpty()) { return null }
|
||||
val relay = if (tag.has(3) && tag[3].isNotBlank()) tag[3] else null
|
||||
val marker = if (tag.has(4) && tag[4].isNotBlank()) tag[4] else null
|
||||
return InputTag(tag[1], tag[2], relay, marker)
|
||||
}
|
||||
|
||||
fun assembleUrl(url: String) = arrayOf(TAG_NAME, url, "url")
|
||||
|
||||
fun assembleText(text: String) = arrayOf(TAG_NAME, text, "text")
|
||||
|
||||
fun assembleEvent(eventId: String) = arrayOf(TAG_NAME, eventId, "event")
|
||||
|
||||
fun assembleJob(jobId: String) = arrayOf(TAG_NAME, jobId, "job")
|
||||
|
||||
fun assemblePrompt(prompt: String) = arrayOf(TAG_NAME, prompt, "prompt")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 2025 Vitor Pamplona
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to use,
|
||||
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
|
||||
* Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
||||
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
package com.vitorpamplona.quartz.nip90Dvms.tags
|
||||
|
||||
import com.vitorpamplona.quartz.nip01Core.core.has
|
||||
import com.vitorpamplona.quartz.utils.ensure
|
||||
|
||||
class OutputTag(
|
||||
val mimeType: String,
|
||||
) {
|
||||
companion object {
|
||||
const val TAG_NAME = "output"
|
||||
|
||||
fun parse(tag: Array<String>): OutputTag? {
|
||||
ensure(tag.has(1)) { return null }
|
||||
ensure(tag[0] == TAG_NAME) { return null }
|
||||
ensure(tag[1].isNotEmpty()) { return null }
|
||||
return OutputTag(tag[1])
|
||||
}
|
||||
|
||||
fun assemble(mimeType: String) = arrayOf(TAG_NAME, mimeType)
|
||||
}
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) 2025 Vitor Pamplona
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to use,
|
||||
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
|
||||
* Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
||||
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
package com.vitorpamplona.quartz.nip90Dvms.tags
|
||||
|
||||
import com.vitorpamplona.quartz.nip01Core.core.Event
|
||||
import com.vitorpamplona.quartz.nip01Core.core.HexKey
|
||||
import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
|
||||
|
||||
fun <T : Event> TagArrayBuilder<T>.inputUrl(url: String) = add(InputTag.assembleUrl(url))
|
||||
|
||||
fun <T : Event> TagArrayBuilder<T>.inputText(text: String) = add(InputTag.assembleText(text))
|
||||
|
||||
fun <T : Event> TagArrayBuilder<T>.inputEvent(eventId: HexKey) = add(InputTag.assembleEvent(eventId))
|
||||
|
||||
fun <T : Event> TagArrayBuilder<T>.inputJob(jobId: HexKey) = add(InputTag.assembleJob(jobId))
|
||||
|
||||
fun <T : Event> TagArrayBuilder<T>.inputPrompt(prompt: String) = add(InputTag.assemblePrompt(prompt))
|
||||
|
||||
fun <T : Event> TagArrayBuilder<T>.output(mimeType: String) = addUnique(OutputTag.assemble(mimeType))
|
||||
|
||||
fun <T : Event> TagArrayBuilder<T>.param(
|
||||
key: String,
|
||||
value: String,
|
||||
) = add(arrayOf("param", key, value))
|
||||
|
||||
fun <T : Event> TagArrayBuilder<T>.param(
|
||||
key: String,
|
||||
vararg values: String,
|
||||
) = add(arrayOf("param", key) + values)
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright (c) 2025 Vitor Pamplona
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to use,
|
||||
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
|
||||
* Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
||||
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
package com.vitorpamplona.quartz.nip90Dvms.tags
|
||||
|
||||
import com.vitorpamplona.quartz.nip01Core.core.TagArray
|
||||
|
||||
fun TagArray.inputs() = mapNotNull(InputTag::parse)
|
||||
|
||||
fun TagArray.outputMimeType() = firstNotNullOfOrNull(OutputTag::parse)?.mimeType
|
||||
+14
@@ -26,6 +26,9 @@ import com.vitorpamplona.quartz.nip01Core.core.HexKey
|
||||
import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
|
||||
import com.vitorpamplona.quartz.nip01Core.signers.eventTemplate
|
||||
import com.vitorpamplona.quartz.nip31Alts.alt
|
||||
import com.vitorpamplona.quartz.nip90Dvms.tags.inputUrl
|
||||
import com.vitorpamplona.quartz.nip90Dvms.tags.output
|
||||
import com.vitorpamplona.quartz.nip90Dvms.tags.param
|
||||
import com.vitorpamplona.quartz.utils.TimeUtils
|
||||
|
||||
@Immutable
|
||||
@@ -42,10 +45,21 @@ class NIP90TextExtractionRequestEvent(
|
||||
const val ALT = "NIP90 Text Extraction request"
|
||||
|
||||
fun build(
|
||||
inputUrl: String,
|
||||
outputMimeType: String? = null,
|
||||
rangeStart: String? = null,
|
||||
rangeEnd: String? = null,
|
||||
alignment: String? = null,
|
||||
createdAt: Long = TimeUtils.now(),
|
||||
initializer: TagArrayBuilder<NIP90TextExtractionRequestEvent>.() -> Unit = {},
|
||||
) = eventTemplate(KIND, "", createdAt) {
|
||||
alt(ALT)
|
||||
inputUrl(inputUrl)
|
||||
outputMimeType?.let { output(it) }
|
||||
if (rangeStart != null && rangeEnd != null) {
|
||||
param("range", rangeStart, rangeEnd)
|
||||
}
|
||||
alignment?.let { param("alignment", it) }
|
||||
initializer()
|
||||
}
|
||||
}
|
||||
|
||||
+19
@@ -26,6 +26,9 @@ import com.vitorpamplona.quartz.nip01Core.core.HexKey
|
||||
import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
|
||||
import com.vitorpamplona.quartz.nip01Core.signers.eventTemplate
|
||||
import com.vitorpamplona.quartz.nip31Alts.alt
|
||||
import com.vitorpamplona.quartz.nip90Dvms.tags.inputPrompt
|
||||
import com.vitorpamplona.quartz.nip90Dvms.tags.output
|
||||
import com.vitorpamplona.quartz.nip90Dvms.tags.param
|
||||
import com.vitorpamplona.quartz.utils.TimeUtils
|
||||
|
||||
@Immutable
|
||||
@@ -42,10 +45,26 @@ class NIP90TextGenerationRequestEvent(
|
||||
const val ALT = "NIP90 Text Generation request"
|
||||
|
||||
fun build(
|
||||
prompt: String,
|
||||
model: String? = null,
|
||||
maxTokens: Int? = null,
|
||||
temperature: Double? = null,
|
||||
topK: Int? = null,
|
||||
topP: Double? = null,
|
||||
frequencyPenalty: Double? = null,
|
||||
outputMimeType: String? = null,
|
||||
createdAt: Long = TimeUtils.now(),
|
||||
initializer: TagArrayBuilder<NIP90TextGenerationRequestEvent>.() -> Unit = {},
|
||||
) = eventTemplate(KIND, "", createdAt) {
|
||||
alt(ALT)
|
||||
inputPrompt(prompt)
|
||||
model?.let { param("model", it) }
|
||||
maxTokens?.let { param("max_tokens", it.toString()) }
|
||||
temperature?.let { param("temperature", it.toString()) }
|
||||
topK?.let { param("top_k", it.toString()) }
|
||||
topP?.let { param("top_p", it.toString()) }
|
||||
frequencyPenalty?.let { param("frequency_penalty", it.toString()) }
|
||||
outputMimeType?.let { output(it) }
|
||||
initializer()
|
||||
}
|
||||
}
|
||||
|
||||
+6
@@ -26,6 +26,8 @@ import com.vitorpamplona.quartz.nip01Core.core.HexKey
|
||||
import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
|
||||
import com.vitorpamplona.quartz.nip01Core.signers.eventTemplate
|
||||
import com.vitorpamplona.quartz.nip31Alts.alt
|
||||
import com.vitorpamplona.quartz.nip90Dvms.tags.inputText
|
||||
import com.vitorpamplona.quartz.nip90Dvms.tags.param
|
||||
import com.vitorpamplona.quartz.utils.TimeUtils
|
||||
|
||||
@Immutable
|
||||
@@ -42,10 +44,14 @@ class NIP90TextToSpeechRequestEvent(
|
||||
const val ALT = "NIP90 Text-to-Speech request"
|
||||
|
||||
fun build(
|
||||
text: String,
|
||||
language: String? = null,
|
||||
createdAt: Long = TimeUtils.now(),
|
||||
initializer: TagArrayBuilder<NIP90TextToSpeechRequestEvent>.() -> Unit = {},
|
||||
) = eventTemplate(KIND, "", createdAt) {
|
||||
alt(ALT)
|
||||
inputText(text)
|
||||
language?.let { param("language", it) }
|
||||
initializer()
|
||||
}
|
||||
}
|
||||
|
||||
+6
@@ -26,6 +26,8 @@ import com.vitorpamplona.quartz.nip01Core.core.HexKey
|
||||
import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
|
||||
import com.vitorpamplona.quartz.nip01Core.signers.eventTemplate
|
||||
import com.vitorpamplona.quartz.nip31Alts.alt
|
||||
import com.vitorpamplona.quartz.nip90Dvms.tags.inputEvent
|
||||
import com.vitorpamplona.quartz.nip90Dvms.tags.param
|
||||
import com.vitorpamplona.quartz.utils.TimeUtils
|
||||
|
||||
@Immutable
|
||||
@@ -42,10 +44,14 @@ class NIP90TranslationRequestEvent(
|
||||
const val ALT = "NIP90 Translation request"
|
||||
|
||||
fun build(
|
||||
eventIds: List<HexKey>,
|
||||
language: String,
|
||||
createdAt: Long = TimeUtils.now(),
|
||||
initializer: TagArrayBuilder<NIP90TranslationRequestEvent>.() -> Unit = {},
|
||||
) = eventTemplate(KIND, "", createdAt) {
|
||||
alt(ALT)
|
||||
eventIds.forEach { inputEvent(it) }
|
||||
param("language", language)
|
||||
initializer()
|
||||
}
|
||||
}
|
||||
|
||||
+12
@@ -26,6 +26,9 @@ import com.vitorpamplona.quartz.nip01Core.core.HexKey
|
||||
import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
|
||||
import com.vitorpamplona.quartz.nip01Core.signers.eventTemplate
|
||||
import com.vitorpamplona.quartz.nip31Alts.alt
|
||||
import com.vitorpamplona.quartz.nip90Dvms.tags.inputUrl
|
||||
import com.vitorpamplona.quartz.nip90Dvms.tags.output
|
||||
import com.vitorpamplona.quartz.nip90Dvms.tags.param
|
||||
import com.vitorpamplona.quartz.utils.TimeUtils
|
||||
|
||||
@Immutable
|
||||
@@ -42,10 +45,19 @@ class NIP90VideoConversionRequestEvent(
|
||||
const val ALT = "NIP90 Video Conversion request"
|
||||
|
||||
fun build(
|
||||
videoUrl: String,
|
||||
outputMimeType: String? = null,
|
||||
rangeStart: String? = null,
|
||||
rangeEnd: String? = null,
|
||||
createdAt: Long = TimeUtils.now(),
|
||||
initializer: TagArrayBuilder<NIP90VideoConversionRequestEvent>.() -> Unit = {},
|
||||
) = eventTemplate(KIND, "", createdAt) {
|
||||
alt(ALT)
|
||||
inputUrl(videoUrl)
|
||||
outputMimeType?.let { output(it) }
|
||||
if (rangeStart != null && rangeEnd != null) {
|
||||
param("range", rangeStart, rangeEnd)
|
||||
}
|
||||
initializer()
|
||||
}
|
||||
}
|
||||
|
||||
+16
@@ -26,6 +26,9 @@ import com.vitorpamplona.quartz.nip01Core.core.HexKey
|
||||
import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
|
||||
import com.vitorpamplona.quartz.nip01Core.signers.eventTemplate
|
||||
import com.vitorpamplona.quartz.nip31Alts.alt
|
||||
import com.vitorpamplona.quartz.nip90Dvms.tags.inputUrl
|
||||
import com.vitorpamplona.quartz.nip90Dvms.tags.output
|
||||
import com.vitorpamplona.quartz.nip90Dvms.tags.param
|
||||
import com.vitorpamplona.quartz.utils.TimeUtils
|
||||
|
||||
@Immutable
|
||||
@@ -42,10 +45,23 @@ class NIP90VideoTranslationRequestEvent(
|
||||
const val ALT = "NIP90 Video Translation request"
|
||||
|
||||
fun build(
|
||||
videoUrl: String,
|
||||
language: String,
|
||||
subtitle: String? = null,
|
||||
rangeStart: String? = null,
|
||||
rangeEnd: String? = null,
|
||||
outputFormat: String? = null,
|
||||
createdAt: Long = TimeUtils.now(),
|
||||
initializer: TagArrayBuilder<NIP90VideoTranslationRequestEvent>.() -> Unit = {},
|
||||
) = eventTemplate(KIND, "", createdAt) {
|
||||
alt(ALT)
|
||||
inputUrl(videoUrl)
|
||||
param("language", language)
|
||||
subtitle?.let { param("subtitle", it) }
|
||||
if (rangeStart != null && rangeEnd != null) {
|
||||
param("range", rangeStart, rangeEnd)
|
||||
}
|
||||
outputFormat?.let { output(it) }
|
||||
initializer()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user