Skip to content

Commit 499dd49

Browse files
committed
feat: support RK examples and env-driven default base URL
1 parent f7f72a6 commit 499dd49

6 files changed

Lines changed: 44 additions & 9 deletions

File tree

‎CONTRIBUTING.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ sdk.dir=/path/to/Android/sdk
1414
5. If you want to run the sample app against the live backend, add your API key to `local.properties`:
1515

1616
```properties
17-
resolvekit.apiKey=iaa_your_key_here
17+
resolvekit.apiKey=rk_your_key_here
18+
resolvekit.baseUrl=https://agent.example.com
1819
```
1920

20-
You can also export `RESOLVEKIT_API_KEY` instead of writing it to `local.properties`.
21+
You can also export `RESOLVEKIT_API_KEY` and `RESOLVEKIT_BASE_URL` instead of writing them to `local.properties`.
2122

2223
For local publishing credentials, copy [.env.example](.env.example) to `.env` and fill in the values you need. Use a base64-encoded private key in `SIGNING_KEY_BASE64`. Keep `.env` local only.
2324

‎README.md‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ Gradle will substitute the local modules automatically.
144144
```kotlin
145145
val runtime = ResolveKitRuntime(
146146
configuration = ResolveKitConfiguration(
147-
apiKeyProvider = { "iaa_your_key_here" },
147+
apiKeyProvider = { "rk_your_key_here" },
148148
functions = listOf(GetCurrentTime)
149149
),
150150
context = applicationContext
@@ -164,7 +164,7 @@ startActivity(
164164
ResolveKitChatActivity.createIntent(
165165
context = this,
166166
configuration = ResolveKitConfiguration(
167-
apiKeyProvider = { "iaa_your_key_here" },
167+
apiKeyProvider = { "rk_your_key_here" },
168168
functions = listOf(GetCurrentTime)
169169
)
170170
)
@@ -179,7 +179,7 @@ supportFragmentManager.beginTransaction()
179179
R.id.container,
180180
ResolveKitChatFragment.newInstance(
181181
ResolveKitConfiguration(
182-
apiKeyProvider = { "iaa_your_key_here" },
182+
apiKeyProvider = { "rk_your_key_here" },
183183
functions = listOf(GetCurrentTime)
184184
)
185185
)
@@ -381,7 +381,8 @@ sdk.dir=/path/to/Android/sdk
381381
3. If you want to run the sample app, also add:
382382

383383
```properties
384-
resolvekit.apiKey=iaa_your_key_here
384+
resolvekit.apiKey=rk_your_key_here
385+
resolvekit.baseUrl=https://agent.example.com
385386
```
386387

387388
4. Select the `sample` run configuration or run:
@@ -484,3 +485,4 @@ This repo includes:
484485
- `local.properties` is intentionally ignored.
485486
- Do not commit API keys or publishing credentials.
486487
- Public API changes should be reflected in this README.
488+
- `RESOLVEKIT_BASE_URL` (or `resolvekit.baseUrl` in `local.properties`) controls the backend URL used by the sample app.

‎sample/build.gradle.kts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ val localProps = Properties().apply {
1313
fun apiKey() = System.getenv("RESOLVEKIT_API_KEY")
1414
?: localProps.getProperty("resolvekit.apiKey")
1515
?: ""
16+
fun baseUrl() = System.getenv("RESOLVEKIT_BASE_URL")
17+
?: localProps.getProperty("resolvekit.baseUrl")
18+
?: "https://agent.example.com"
1619

1720
android {
1821
namespace = "app.resolvekit.sample"
@@ -26,6 +29,7 @@ android {
2629
versionName = "1.0.0"
2730

2831
buildConfigField("String", "RESOLVEKIT_API_KEY", "\"${apiKey()}\"")
32+
buildConfigField("String", "RESOLVEKIT_BASE_URL", "\"${baseUrl()}\"")
2933
}
3034

3135
buildFeatures {

‎sample/src/main/kotlin/app/resolvekit/sample/MainActivity.kt‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ import app.resolvekit.ui.ResolveKitRuntime
1313
*
1414
* Set RESOLVEKIT_API_KEY in your environment (or local.properties) before
1515
* running:
16-
* RESOLVEKIT_API_KEY=iaa_... ./gradlew :sample:installDebug
16+
* RESOLVEKIT_API_KEY=rk_... ./gradlew :sample:installDebug
1717
*/
1818
class MainActivity : ComponentActivity() {
1919

2020
private val runtime by lazy {
2121
ResolveKitRuntime(
2222
configuration = ResolveKitConfiguration(
23+
baseUrl = BuildConfig.RESOLVEKIT_BASE_URL,
2324
apiKeyProvider = { BuildConfig.RESOLVEKIT_API_KEY.takeIf { it.isNotBlank() } },
2425
llmContextProvider = {
2526
// Provide custom context to shape LLM responses

‎ui/src/main/kotlin/app/resolvekit/ui/ResolveKitConfiguration.kt‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,24 @@ import app.resolvekit.core.AnyResolveKitFunction
44
import app.resolvekit.core.JSONObject
55
import app.resolvekit.core.ResolveKitFunctionPack
66

7+
object ResolveKitDefaults {
8+
const val BASE_URL_ENV_KEY = "RESOLVEKIT_BASE_URL"
9+
const val fallbackBaseUrl = "https://agent.example.com"
10+
11+
internal fun resolveBaseUrl(
12+
envLookup: (String) -> String? = System::getenv,
13+
propertyLookup: (String) -> String? = System::getProperty
14+
): String {
15+
val configured = sequenceOf(
16+
propertyLookup(BASE_URL_ENV_KEY),
17+
envLookup(BASE_URL_ENV_KEY)
18+
).firstOrNull { !it.isNullOrBlank() }?.trim()
19+
return configured ?: fallbackBaseUrl
20+
}
21+
22+
val baseUrl: String = resolveBaseUrl()
23+
}
24+
725
/**
826
* Immutable configuration for [ResolveKitRuntime].
927
*
@@ -24,7 +42,7 @@ import app.resolvekit.core.ResolveKitFunctionPack
2442
* @param functionPacks Grouped tool modules; all functions in each pack are registered.
2543
*/
2644
data class ResolveKitConfiguration(
27-
val baseUrl: String = "https://agent.example.com",
45+
val baseUrl: String = ResolveKitDefaults.baseUrl,
2846
val apiKeyProvider: () -> String?,
2947
val deviceIdProvider: (() -> String?)? = null,
3048
val llmContextProvider: () -> JSONObject = { emptyMap() },

‎ui/src/test/kotlin/app/resolvekit/ui/ResolveKitRuntimeTest.kt‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,16 @@ class ResolveKitRuntimeTest {
6060
@Test
6161
fun `configuration defaults to neutral self-host base URL`() {
6262
val config = ResolveKitConfiguration(apiKeyProvider = { "test-key" })
63-
assertEquals("https://agent.example.com", config.baseUrl)
63+
assertEquals(ResolveKitDefaults.fallbackBaseUrl, config.baseUrl)
64+
}
65+
66+
@Test
67+
fun `configuration default base URL supports environment override`() {
68+
val resolved = ResolveKitDefaults.resolveBaseUrl(
69+
envLookup = { null },
70+
propertyLookup = { if (it == ResolveKitDefaults.BASE_URL_ENV_KEY) "https://agent.selfhost.example.com" else null }
71+
)
72+
assertEquals("https://agent.selfhost.example.com", resolved)
6473
}
6574

6675
@Test

0 commit comments

Comments
 (0)