Repository navigation
Add native card renderers for custom response element types #196
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
Merged
Merged
Changes from 15 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
3a871f9
Merge pull request #187 from adobe/dev
rymorale f407466
Merge pull request #188 from adobe/staging
rymorale 1d89653
Merge pull request #192 from adobe/dev
rymorale 398f787
Merge pull request #193 from adobe/staging
rymorale 955f0c5
Add native card renderers for custom response element types
89aa0c9
Merge remote-tracking branch 'origin/dev' into feature/native-card-pl…
e1eca42
nit: collapsing in one function
429eb66
Initial commit: Kings specific native card plugins
05305fa
Merge pull request #202 from adobe/dev
rymorale 9aa3119
Merge pull request #204 from adobe/staging
rymorale b96888d
Fix native card delivery and fallback handling; add offline edge-case…
9e3fe32
Exclude local-only renderer edge-case demo from PR
c088d67
Clarify generic native card renderer documentation
6a52c85
Merge branch 'adobe:main' into feature/native-card-plugins-v1
BNanda99 43ffaae
Address native card review feedback
54aca35
Fix native card reset and suffix alignment
2ec024b
Add sequence and isLatest to native card context
b8b5523
[MAR-2699] Render CSS box-shadow for input bar and product cards
rymorale e475f67
[MAR-2699] Review update and add coverage
rymorale 13dbfa8
Merge pull request #212 from rymorale/input-box-drop-shadow
rymorale 4d26f1d
Route custom cards by renderer ID
ac41aba
Omit custom elements without an accepted renderer
cc524b4
Show errors and keep suggestions when nothing renders
d9e4996
Handle empty responses when the stream drops after completion
1262406
Keep native card staleness reserved
8c1f69d
Merge branch 'adobe:main' into feature/native-card-plugins-v1
BNanda99 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
34 changes: 34 additions & 0 deletions
34
code/concierge/src/main/kotlin/com/adobe/marketing/mobile/concierge/ConciergeCardRenderer.kt
This file contains hidden or 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,34 @@ | ||
| /* | ||
| * Copyright 2026 Adobe. All rights reserved. | ||
| * This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. You may obtain a copy | ||
| * of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software distributed under | ||
| * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
| * OF ANY KIND, either express or implied. See the License for the specific language | ||
| * governing permissions and limitations under the License. | ||
| */ | ||
|
|
||
| package com.adobe.marketing.mobile.concierge | ||
|
|
||
| import androidx.compose.runtime.Composable | ||
|
|
||
| /** | ||
| * Renders one transcript card for a response element whose `type` was registered with | ||
| * [Concierge.registerCardRenderer]. | ||
| * | ||
| * - `element`: the complete, read-only element dictionary from `multimodalElements.elements`. | ||
| * - `context`: read-only card context, rebuilt on every recomposition: `cardId`, `sessionId`, | ||
| * `conversationId`, `interactionId` (each may be absent), `isBusy`, `isStale`, and `state` | ||
| * (this card's last saved state, if any). | ||
| * - `saveState`: replaces this card's private state. Callable from any thread; applied on the main | ||
| * thread. Never sent to Brand Concierge. | ||
| * | ||
| * Renderers must not throw, and must not start work during composition. | ||
| */ | ||
| typealias ConciergeCardRenderer = @Composable ( | ||
| element: Map<String, Any?>, | ||
| context: Map<String, Any?>, | ||
| saveState: (Map<String, Any?>) -> Unit | ||
| ) -> Unit |
69 changes: 69 additions & 0 deletions
69
code/concierge/src/main/kotlin/com/adobe/marketing/mobile/concierge/cards/CardJson.kt
This file contains hidden or 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,69 @@ | ||
| /* | ||
| * Copyright 2026 Adobe. All rights reserved. | ||
| * This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. You may obtain a copy | ||
| * of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software distributed under | ||
| * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
| * OF ANY KIND, either express or implied. See the License for the specific language | ||
| * governing permissions and limitations under the License. | ||
| */ | ||
|
|
||
| package com.adobe.marketing.mobile.concierge.cards | ||
|
|
||
| import java.math.BigDecimal | ||
| import java.math.BigInteger | ||
| import java.util.Collections | ||
|
|
||
| /** | ||
| * JSON value model for response elements, renderer actions, and action results: | ||
| * `String`, `Boolean`, finite `Number`, `null`, `List`, and string-keyed `Map`. | ||
| */ | ||
| internal object CardJson { | ||
| private const val MAX_DEPTH = 64 | ||
| private const val MAX_NODES = 100_000 | ||
|
|
||
| private class CopyBudget(var remaining: Int = MAX_NODES) { | ||
| fun consume(path: String) { | ||
| require(remaining > 0) { "$path exceeds the $MAX_NODES value limit" } | ||
| remaining-- | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Returns a deep, read-only copy of [value], preserving nulls and number types. | ||
| * | ||
| * @throws IllegalArgumentException naming the path of the first unsupported value. | ||
| */ | ||
| fun readOnlyCopy(value: Map<*, *>): Map<String, Any?> = copyObject(value, "$", 0, CopyBudget()) | ||
|
|
||
| private fun copyObject(value: Map<*, *>, path: String, depth: Int, budget: CopyBudget): Map<String, Any?> { | ||
| require(depth < MAX_DEPTH) { "$path nests deeper than $MAX_DEPTH levels" } | ||
| budget.consume(path) | ||
| require(value.size <= budget.remaining) { "$path exceeds the $MAX_NODES value limit" } | ||
| val copy = LinkedHashMap<String, Any?>(value.size) | ||
| for ((key, entry) in value) { | ||
| require(key is String) { "$path has a non-string key" } | ||
| copy[key] = copyValue(entry, "$path.$key", depth + 1, budget) | ||
| } | ||
| return Collections.unmodifiableMap(copy) | ||
| } | ||
|
|
||
| private fun copyValue(value: Any?, path: String, depth: Int, budget: CopyBudget): Any? = when (value) { | ||
| is Map<*, *> -> copyObject(value, path, depth, budget) | ||
| is List<*> -> { | ||
| require(depth < MAX_DEPTH) { "$path nests deeper than $MAX_DEPTH levels" } | ||
| budget.consume(path) | ||
| require(value.size <= budget.remaining) { "$path exceeds the $MAX_NODES value limit" } | ||
| Collections.unmodifiableList(value.mapIndexed { index, item -> copyValue(item, "$path[$index]", depth + 1, budget) }) | ||
| } | ||
| null, is String, is Boolean -> value.also { budget.consume(path) } | ||
| is Double, is Float -> value.also { | ||
| require((value as Number).toDouble().isFinite()) { "$path is not a finite number" } | ||
| budget.consume(path) | ||
| } | ||
| is Int, is Long, is Short, is Byte, is BigDecimal, is BigInteger -> value.also { budget.consume(path) } | ||
| else -> throw IllegalArgumentException("$path has an unsupported ${value.javaClass.simpleName} value") | ||
| } | ||
| } | ||
33 changes: 33 additions & 0 deletions
33
...erge/src/main/kotlin/com/adobe/marketing/mobile/concierge/cards/ConciergeCardRenderers.kt
This file contains hidden or 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,33 @@ | ||
| /* | ||
| * Copyright 2026 Adobe. All rights reserved. | ||
| * This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. You may obtain a copy | ||
| * of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software distributed under | ||
| * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
| * OF ANY KIND, either express or implied. See the License for the specific language | ||
| * governing permissions and limitations under the License. | ||
| */ | ||
|
|
||
| package com.adobe.marketing.mobile.concierge.cards | ||
|
|
||
| import com.adobe.marketing.mobile.concierge.ConciergeCardRenderer | ||
| import java.util.concurrent.ConcurrentHashMap | ||
|
|
||
| /** Process-wide card renderers by exact element `type`; the last registration wins. */ | ||
| internal object ConciergeCardRenderers { | ||
| private val renderers = ConcurrentHashMap<String, ConciergeCardRenderer>() | ||
|
|
||
| fun register(type: String, renderer: ConciergeCardRenderer) { | ||
|
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. Do we also need a way to un-register the renderer?
Member
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. this can be added as an enhancement for later. |
||
| require(type.isNotBlank()) { "Card renderer type must not be blank." } | ||
| renderers[type] = renderer | ||
| } | ||
|
|
||
| fun rendererFor(type: String?): ConciergeCardRenderer? = type?.let(renderers::get) | ||
|
|
||
| val hasAnyRenderer: Boolean | ||
| get() = renderers.isNotEmpty() | ||
|
|
||
| internal fun clear() = renderers.clear() | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am wondering if it is safe to replace
CardJsonwith a smalltoJsonSafe()extension something like below