-
Notifications
You must be signed in to change notification settings - Fork 247
feat: add tasks models #566
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
23885ce
230982e
0f10a47
06e237a
4a20fe2
2fe7e7c
8219bf1
f678b5d
8060cd5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ import kotlinx.serialization.Serializable | |
| import kotlinx.serialization.json.JsonElement | ||
| import kotlinx.serialization.json.JsonObject | ||
| import kotlinx.serialization.json.JsonPrimitive | ||
| import kotlinx.serialization.json.decodeFromJsonElement | ||
| import kotlinx.serialization.json.long | ||
| import kotlinx.serialization.json.longOrNull | ||
| import kotlin.jvm.JvmInline | ||
|
|
@@ -22,6 +23,17 @@ public value class RequestMeta(public val json: JsonObject) { | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * The related task metadata, if this request is associated with a task. | ||
| * | ||
| * @see RelatedTaskMetadata | ||
| * @see RELATED_TASK_META_KEY | ||
| */ | ||
| public val relatedTask: RelatedTaskMetadata? | ||
| get() = json[RELATED_TASK_META_KEY]?.let { element -> | ||
| McpJson.decodeFromJsonElement(element) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we cache it or handle during deserialization in the serializer? Currently, it will run json parsing every time
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. json is not parsed every time, It’s not an expensive operation I can do it that way, but then we’ll have to modify the class since it’s
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
And that would require a custom serializer, which I’d prefer to avoid
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. json is not parsed every time, It’s not an expensive operation I see the getter is not cached, so every property call will result in json parsing. In general, it should be avoided. The application would have to cache it. A value class may not be the best solution here, as it introduces unnecessary restrictions. Additionally, An alternative solution is to use an extension function: public fun RequestMeta.relatedTaskMetadata(): RelatedTaskMetadata? = this.json[RELATED_TASK_META_KEY]?.let {
McpJson.decodeFromJsonElement(it)
}This approach is more extensible and avoids the pitfalls of the current solution, even if it doesn't address the lack of caching.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
To clarify,
The relatedTask property was intentionally implemented to be consistent with |
||
| } | ||
|
|
||
| /** | ||
| * Retrieves the value associated with the specified key from the JSON object. | ||
| * | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.