diff --git a/src/commonMain/kotlin/tool/Tools.kt b/src/commonMain/kotlin/tool/Tools.kt index d42e538..adb4781 100644 --- a/src/commonMain/kotlin/tool/Tools.kt +++ b/src/commonMain/kotlin/tool/Tools.kt @@ -61,9 +61,9 @@ inline fun toolOf( val serializer = try { serializer() - } catch (e :SerializationException) { + } catch (e: SerializationException) { throw SerializationException( - "The class ${T::class.qualifiedName} must be annotated with @SerializableTool", e + nonAnnotatedToolMessage(), e ) } @@ -72,7 +72,7 @@ inline fun toolOf( .annotations .filterIsInstance() .firstOrNull() ?: throw SerializationException( - "The class ${T::class.qualifiedName} must be annotated with @SerializableTool", + nonAnnotatedToolMessage() ) return Tool( @@ -82,3 +82,7 @@ inline fun toolOf( cacheControl = cacheControl ) } + +@PublishedApi +internal inline fun nonAnnotatedToolMessage() = + "The class ${T::class.qualifiedName} must be annotated with @AnthropicTool" diff --git a/src/commonTest/kotlin/tool/UsableToolTest.kt b/src/commonTest/kotlin/tool/UsableToolTest.kt index 5f06379..c585edb 100644 --- a/src/commonTest/kotlin/tool/UsableToolTest.kt +++ b/src/commonTest/kotlin/tool/UsableToolTest.kt @@ -68,7 +68,7 @@ class UsableToolTest { @Test fun shouldFailToCreateToolWithoutAnthropicToolAnnotation() { shouldThrowWithMessage( - "The class com.xemantic.anthropic.tool.UsableToolTest.NoAnnotationTool must be annotated with @SerializableTool" + "The class com.xemantic.anthropic.tool.UsableToolTest.NoAnnotationTool must be annotated with @AnthropicTool" ) { toolOf() } @@ -84,7 +84,7 @@ class UsableToolTest { @Test fun shouldFailToCreateToolWithOnlySerializableAnnotation() { shouldThrowWithMessage( - "The class com.xemantic.anthropic.tool.UsableToolTest.OnlySerializableAnnotationTool must be annotated with @SerializableTool" + "The class com.xemantic.anthropic.tool.UsableToolTest.OnlySerializableAnnotationTool must be annotated with @AnthropicTool" ) { toolOf() }