-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #88 from mkouba/issue-85-encoders
core: introduce API to encode return values as response objects
- Loading branch information
Showing
29 changed files
with
1,262 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
core/runtime/src/main/java/io/quarkiverse/mcp/server/ContentEncoder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package io.quarkiverse.mcp.server; | ||
|
||
import jakarta.annotation.Priority; | ||
|
||
/** | ||
* Encodes an object as {@link Content}. | ||
* <p> | ||
* Implementation classes must be CDI beans. Qualifiers are ignored. {@link jakarta.enterprise.context.Dependent} beans are | ||
* reused during encoding. | ||
* <p> | ||
* Encoders may define the priority with {@link Priority}. An encoder with higher priority takes precedence. | ||
* | ||
* @param <TYPE> | ||
* @see Content | ||
* @see Tool | ||
* @see Prompt | ||
*/ | ||
public interface ContentEncoder<TYPE> extends Encoder<TYPE, Content> { | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
core/runtime/src/main/java/io/quarkiverse/mcp/server/Encoder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package io.quarkiverse.mcp.server; | ||
|
||
/** | ||
* | ||
* @param <TYPE> The type to be encoded | ||
* @param <ENCODED> The resulting type of encoding | ||
*/ | ||
public interface Encoder<TYPE, ENCODED> { | ||
|
||
/** | ||
* | ||
* @param runtimeType The runtime class of an object that should be encoded, must not be {@code null} | ||
* @return {@code true} if this encoder can encode the provided type, {@code false} otherwise | ||
*/ | ||
boolean supports(Class<?> runtimeType); | ||
|
||
/** | ||
* | ||
* @param value | ||
* @return the encoded value | ||
*/ | ||
ENCODED encode(TYPE value); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
core/runtime/src/main/java/io/quarkiverse/mcp/server/PromptResponseEncoder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package io.quarkiverse.mcp.server; | ||
|
||
import jakarta.annotation.Priority; | ||
|
||
/** | ||
* Encodes an object as {@link PromptResponse}. | ||
* <p> | ||
* If a propmpt response encoder exists and matches a specific return type then it always takes precedence over matching | ||
* {@link ContentEncoder}. | ||
* <p> | ||
* Implementation classes must be CDI beans. Qualifiers are ignored. {@link jakarta.enterprise.context.Dependent} beans are | ||
* reused during encoding. | ||
* <p> | ||
* Encoders may define the priority with {@link Priority}. An encoder with higher priority takes precedence. | ||
* | ||
* @param <TYPE> | ||
* @see PromptResponse | ||
* @see Prompt | ||
*/ | ||
public interface PromptResponseEncoder<TYPE> extends Encoder<TYPE, PromptResponse> { | ||
|
||
} |
Oops, something went wrong.