catalyst-ai 1.1.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -44,4 +44,8 @@ dependencies {
44
44
 
45
45
  implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.9.0")
46
46
  implementation("org.json:json:20231013")
47
+
48
+ testImplementation("junit:junit:4.13.2")
49
+ // Use the real JSON implementation instead of android.jar's stub methods.
50
+ testImplementation("org.json:json:20231013")
47
51
  }
@@ -0,0 +1,34 @@
1
+ package io.catalyst.nativeai
2
+
3
+ import org.json.JSONObject
4
+
5
+ /** Builds app and optional attachment instructions without loading the native model. */
6
+ internal fun buildAISystemPrompt(options: JSONObject, log: (String) -> Unit = {}): String {
7
+ val attachmentComponents = options.optJSONObject("attachmentComponents")
8
+ if (attachmentComponents == null || attachmentComponents.length() == 0) {
9
+ // No components to describe, but the app's own systemPrompt must still reach the model.
10
+ val systemPrompt = options.optString("systemPrompt", "").trim()
11
+ log("[attachments] No attachmentComponents provided — using the app systemPrompt only (${systemPrompt.length} chars)")
12
+ return systemPrompt
13
+ }
14
+
15
+ log("[attachments] Received ${attachmentComponents.length()} component(s): ${attachmentComponents.keys().asSequence().joinToString()}")
16
+ val appSystemPrompt = options.optString("systemPrompt", "").trim()
17
+ val sb = StringBuilder()
18
+ if (appSystemPrompt.isNotBlank()) {
19
+ sb.appendLine(appSystemPrompt)
20
+ sb.appendLine()
21
+ }
22
+ sb.appendLine("Never use markdown headers, bullet points, numbered lists, or bold. Instead use these components: <tool:create_attachment component='Name' [attr='val']>body</tool:create_attachment>")
23
+ sb.append("Available components: ")
24
+ val componentSummary = attachmentComponents.keys().asSequence().map { name ->
25
+ val def = attachmentComponents.optJSONObject(name)
26
+ val hint = def?.optString("hint", "")?.trim() ?: ""
27
+ if (hint.isNotBlank()) "$name ($hint)" else name
28
+ }.joinToString(", ")
29
+ sb.appendLine(componentSummary)
30
+ attachmentComponents.keys().forEach { name -> log("[attachments] Registered component: $name") }
31
+ val systemPrompt = sb.toString().trim()
32
+ log("[attachments] System prompt set (${systemPrompt.length} chars)")
33
+ return systemPrompt
34
+ }
@@ -123,32 +123,7 @@ class NativeBridgeAI(
123
123
  // -------------------------------------------------------------------------
124
124
 
125
125
  private fun buildSystemPrompt(options: JSONObject) {
126
- val attachmentComponents = options.optJSONObject("attachmentComponents")
127
- if (attachmentComponents == null || attachmentComponents.length() == 0) {
128
- // No components to describe, but the app's own systemPrompt must still reach the model.
129
- systemPrompt = options.optString("systemPrompt", "").trim()
130
- log("[attachments] No attachmentComponents provided — using the app systemPrompt only (${systemPrompt.length} chars)")
131
- return
132
- }
133
-
134
- log("[attachments] Received ${attachmentComponents.length()} component(s): ${attachmentComponents.keys().asSequence().joinToString()}")
135
- val appSystemPrompt = options.optString("systemPrompt", "").trim()
136
- val sb = StringBuilder()
137
- if (appSystemPrompt.isNotBlank()) {
138
- sb.appendLine(appSystemPrompt)
139
- sb.appendLine()
140
- }
141
- sb.appendLine("Never use markdown headers, bullet points, numbered lists, or bold. Instead use these components: <tool:create_attachment component='Name' [attr='val']>body</tool:create_attachment>")
142
- sb.append("Available components: ")
143
- val componentSummary = attachmentComponents.keys().asSequence().map { name ->
144
- val def = attachmentComponents.optJSONObject(name)
145
- val hint = def?.optString("hint", "")?.trim() ?: ""
146
- if (hint.isNotBlank()) "$name ($hint)" else name
147
- }.joinToString(", ")
148
- sb.appendLine(componentSummary)
149
- attachmentComponents.keys().forEach { name -> log("[attachments] Registered component: $name") }
150
- systemPrompt = sb.toString().trim()
151
- log("[attachments] System prompt set (${systemPrompt.length} chars)")
126
+ systemPrompt = buildAISystemPrompt(options, ::log)
152
127
  }
153
128
 
154
129
  private fun resolveModel(options: JSONObject): String {
@@ -0,0 +1,45 @@
1
+ package io.catalyst.nativeai
2
+
3
+ import org.json.JSONObject
4
+ import org.junit.Assert.assertEquals
5
+ import org.junit.Assert.assertFalse
6
+ import org.junit.Assert.assertTrue
7
+ import org.junit.Test
8
+
9
+ /** Regression coverage for #542 without initializing or downloading a model. */
10
+ class NativeBridgeAISystemPromptTest {
11
+ private fun build(options: String): String = buildAISystemPrompt(JSONObject(options))
12
+
13
+ @Test
14
+ fun appPromptIsPreservedWithoutComponents() {
15
+ assertEquals("Answer only in French.", build("""{"systemPrompt":" Answer only in French. "}"""))
16
+ }
17
+
18
+ @Test
19
+ fun appPromptIsPreservedWithEmptyComponents() {
20
+ assertEquals("Return JSON only.", build("""{"systemPrompt":"Return JSON only.","attachmentComponents":{}}"""))
21
+ }
22
+
23
+ @Test
24
+ fun missingOrBlankPromptWithoutComponentsProducesNoInstructions() {
25
+ assertEquals("", build("{}"))
26
+ assertEquals("", build("""{"systemPrompt":" \n\t "}"""))
27
+ assertEquals("", build("""{"systemPrompt":" ","attachmentComponents":{}}"""))
28
+ }
29
+
30
+ @Test
31
+ fun attachmentInstructionsFollowTheAppPrompt() {
32
+ val prompt = build("""{"systemPrompt":" Answer in French. ","attachmentComponents":{"Card":{"hint":" Show a card "}}}""")
33
+ assertTrue(prompt.startsWith("Answer in French.\n\nNever use markdown"))
34
+ assertTrue(prompt.contains("<tool:create_attachment component='Name'"))
35
+ assertTrue(prompt.endsWith("Available components: Card (Show a card)"))
36
+ }
37
+
38
+ @Test
39
+ fun componentsWithoutAppPromptStillReceiveInstructions() {
40
+ val prompt = build("""{"attachmentComponents":{"Card":{}}}""")
41
+ assertTrue(prompt.startsWith("Never use markdown"))
42
+ assertTrue(prompt.endsWith("Available components: Card"))
43
+ assertFalse(prompt.contains("Card ()"))
44
+ }
45
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "catalyst-ai",
3
- "version": "1.1.0",
3
+ "version": "1.3.0",
4
4
  "description": "AI provider for catalyst-core — cloud/web/native useAI hooks + OpenAI/Gemini SSE route",
5
5
  "main": "src/index.js",
6
6
  "exports": {