Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions .github/workflows/project_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,66 @@ permissions:
contents: read

jobs:
detect-mnn-changes:
name: Detect MNN changes
runs-on: ubuntu-24.04
outputs:
has-mnn-changes: ${{ steps.changes.outputs.has-mnn-changes }}
steps:
- name: Checkout complete history
uses: actions/checkout@v4.1.0
with:
fetch-depth: 0
persist-credentials: false
- name: Check the complete change range
id: changes
env:
EVENT_NAME: ${{ github.event_name }}
PR_BASE_SHA: ${{ github.event.pull_request.base.sha }}
PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
PUSH_BASE_SHA: ${{ github.event.before }}
PUSH_HEAD_SHA: ${{ github.sha }}
shell: bash
run: |
# PRs include every branch commit; pushes include every commit in the push.
# If history is unavailable (e.g. a force push), run the checks conservatively.
has_mnn_changes=true
if [[ "$EVENT_NAME" == pull_request ]]; then
head="$PR_HEAD_SHA"
base=$(git merge-base "$PR_BASE_SHA" "$head") || base=''
else
head="$PUSH_HEAD_SHA"
base="$PUSH_BASE_SHA"
fi

if [[ -n "$base" && ! "$base" =~ ^0+$ ]] &&
git diff --name-only --no-renames -z "$base" "$head" -- > "$RUNNER_TEMP/mnn-changed-paths"; then
has_mnn_changes=false
while IFS= read -r -d '' path; do
case "$path" in
*[Mm][Nn][Nn]*|app/ios/*|build.gradle.kts|settings.gradle.kts|gradle.properties|gradlew|gradlew.bat|gradle/*|build-logic/*|*/build.gradle.kts|*/DownloadableModelResponse.kt)
has_mnn_changes=true
break
;;
esac
done < "$RUNNER_TEMP/mnn-changed-paths"

# Shared DI and provider files can contain MNN code without MNN in their paths.
if [[ "$has_mnn_changes" == false ]]; then
# Editing this gate must not trigger the native builds itself.
git diff --name-only --no-renames -G '[Mm][Nn][Nn]' "$base" "$head" -- . ':(exclude).github/workflows/project_tests.yml' > "$RUNNER_TEMP/mnn-changed-code"
if [[ -s "$RUNNER_TEMP/mnn-changed-code" ]]; then
has_mnn_changes=true
fi
fi
fi
echo "has-mnn-changes=$has_mnn_changes" >> "$GITHUB_OUTPUT"
echo "MNN changes in $base..$head: $has_mnn_changes" >> "$GITHUB_STEP_SUMMARY"

test-mnn:
name: MNN — ${{ matrix.platform }} contracts and native tests
needs: detect-mnn-changes
if: needs.detect-mnn-changes.outputs.has-mnn-changes == 'true'
strategy:
fail-fast: false
matrix:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ sealed interface ChipTextFieldEvent<T : Any> {
*
* @param modifier Layout modifiers for the complete outlined chip field.
* @param label Optional field-caption content.
* @param trailingIcon Optional action content at the outlined field’s trailing edge.
* @param textStyle Style for the pending unsubmitted text.
* @param textFieldValueState Mutable pending text and cursor selection retained by the caller.
* @param chips Current ordered chip values; mutations are reported through events.
Expand All @@ -109,6 +110,7 @@ sealed interface ChipTextFieldEvent<T : Any> {
fun ChipTextField(
modifier: Modifier = Modifier,
label: @Composable (() -> Unit)? = null,
trailingIcon: @Composable (() -> Unit)? = null,
textStyle: TextStyle = TextStyle.Default,
textFieldValueState: MutableState<TextFieldValue> = remember { mutableStateOf(TextFieldValue()) },
chips: List<String> = remember { emptyList() },
Expand All @@ -122,6 +124,7 @@ fun ChipTextField(
ChipTextField(
modifier = modifier,
label = label,
trailingIcon = trailingIcon,
textStyle = textStyle,
textFieldValueState = textFieldValueState,
chips = chips,
Expand All @@ -142,6 +145,7 @@ fun ChipTextField(
*
* @param modifier Layout modifiers for the complete outlined chip field.
* @param label Optional field-caption content.
* @param trailingIcon Optional action content at the outlined field’s trailing edge.
* @param textStyle Style for the pending unsubmitted text.
* @param textFieldValueState Mutable pending text and cursor selection retained by the caller.
* @param chips Current ordered chip values; mutations are reported through events.
Expand All @@ -160,6 +164,7 @@ fun ChipTextField(
fun <T : Any> ChipTextField(
modifier: Modifier = Modifier,
label: @Composable (() -> Unit)? = null,
trailingIcon: @Composable (() -> Unit)? = null,
textStyle: TextStyle = TextStyle.Default,
textFieldValueState: MutableState<TextFieldValue> = remember { mutableStateOf(TextFieldValue()) },
chips: List<T> = remember { emptyList() },
Expand Down Expand Up @@ -189,6 +194,7 @@ fun <T : Any> ChipTextField(
) {
TextFieldDefaults.DecorationBox(
label = label,
trailingIcon = trailingIcon,
value = textFieldValueState.value.text + if (chips.isNotEmpty()) " " else "",
innerTextField = {
FlowRow(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.shifthackz.aisdv1.presentation.components.widget.input.chip

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.material3.LocalTextStyle
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
Expand All @@ -18,6 +19,7 @@ import com.shifthackz.aisdv1.presentation.components.utils.ExtrasFormatter
* @param modifier Layout modifiers for the prompt-tag field.
* @param textFieldValueState Caller-owned pending text and selection.
* @param label Localized field caption.
* @param trailingIcon Optional action content at the outlined field’s trailing edge.
* @param list Ordered prompt tags currently shown as chips.
* @param onItemClick Opens the tag editor with the clicked zero-based index and tag text.
* @param onEvent Receives requested additions, batch additions, edits or removals.
Expand All @@ -30,14 +32,16 @@ fun ChipTextFieldWithItem(
textFieldValueState: MutableState<TextFieldValue>,
label: UiText,
list: List<String>,
trailingIcon: @Composable (() -> Unit)? = null,
onItemClick: (type: Int, item: String) -> Unit = { _, _ -> },
onEvent: (event: ChipTextFieldEvent<String>) -> Unit,
) {
ChipTextField(
modifier = modifier,
label = { Text(label.asString()) },
trailingIcon = trailingIcon,
textFieldValueState = textFieldValueState,
textStyle = LocalTextStyle.current,
textStyle = LocalTextStyle.current.copy(color = MaterialTheme.colorScheme.onSurface),
chips = list,
horizontalArrangement = Arrangement.spacedBy(4.dp),
verticalArrangement = Arrangement.spacedBy(4.dp),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.shifthackz.aisdv1.presentation.generation.widget.input

import com.shifthackz.aisdv1.presentation.components.widget.input.PlatformOutlinedTextField

import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Close
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
Expand All @@ -13,11 +15,13 @@ import androidx.compose.ui.text.input.TextFieldValue
import androidx.compose.ui.unit.dp
import com.shifthackz.aisdv1.core.localization.Localization
import com.shifthackz.aisdv1.core.model.asUiText
import com.shifthackz.aisdv1.presentation.components.widget.input.PlatformOutlinedTextField
import com.shifthackz.aisdv1.presentation.components.widget.input.chip.ChipTextFieldWithItem

/**
* Displays either prompt through one shared editor structure. Text and chip selection remain
* owned by the screen; scrolling a field out of view does not own or clear its generation value.
* owned by the screen. Clearing removes both submitted tags and pending text for this prompt.
* Scrolling a field out of view does not own or clear its generation value.
*
* @param prompt Current positive prompt used when opening a tag editor.
* @param negativePrompt Current negative prompt used when opening a tag editor.
Expand Down Expand Up @@ -50,21 +54,39 @@ internal fun GenerationPromptEditor(
else GenerationInputFormEvent.UpdatePrompt(value),
)
}
val value = if (isNegative) negativePrompt else prompt
val hasContent = value.isNotEmpty() ||
(isTaggedInputEnabled && (keywords.isNotEmpty() || chipTextFieldState.value.text.isNotEmpty()))
val clearAction: @Composable (() -> Unit)? = if (hasContent) {
{
IconButton(onClick = {
chipTextFieldState.value = TextFieldValue()
onPromptChange("")
}) {
Icon(
imageVector = Icons.Default.Close,
contentDescription = Localization.string("action_clear"),
)
}
}
} else null
if (isTaggedInputEnabled) {
ChipTextFieldWithItem(
modifier = modifier.fillMaxWidth().padding(top = 8.dp),
textFieldValueState = chipTextFieldState,
label = Localization.string(labelKey).asUiText(),
list = keywords,
trailingIcon = clearAction,
onItemClick = { _, tag ->
onEvent(GenerationInputFormEvent.EditTag(prompt, negativePrompt, tag, isNegative))
},
) { event -> onPromptChange(processTaggedPrompt(keywords, event)) }
} else {
PlatformOutlinedTextField(
modifier = modifier.fillMaxWidth().padding(top = 8.dp),
value = if (isNegative) negativePrompt else prompt,
value = value,
onValueChange = onPromptChange,
trailingIcon = clearAction,
label = Localization.string(labelKey),
containerColor = textFieldContainerColor,
textColor = MaterialTheme.colorScheme.onSurface,
Expand Down
Loading