diff --git a/.github/workflows/project_tests.yml b/.github/workflows/project_tests.yml index b36ab6efe..0a61a8aa0 100644 --- a/.github/workflows/project_tests.yml +++ b/.github/workflows/project_tests.yml @@ -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: diff --git a/presentation/components/src/commonMain/kotlin/com/shifthackz/aisdv1/presentation/components/widget/input/chip/ChipTextField.kt b/presentation/components/src/commonMain/kotlin/com/shifthackz/aisdv1/presentation/components/widget/input/chip/ChipTextField.kt index 97a6df355..a0b43b0b2 100644 --- a/presentation/components/src/commonMain/kotlin/com/shifthackz/aisdv1/presentation/components/widget/input/chip/ChipTextField.kt +++ b/presentation/components/src/commonMain/kotlin/com/shifthackz/aisdv1/presentation/components/widget/input/chip/ChipTextField.kt @@ -93,6 +93,7 @@ sealed interface ChipTextFieldEvent { * * @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. @@ -109,6 +110,7 @@ sealed interface ChipTextFieldEvent { fun ChipTextField( modifier: Modifier = Modifier, label: @Composable (() -> Unit)? = null, + trailingIcon: @Composable (() -> Unit)? = null, textStyle: TextStyle = TextStyle.Default, textFieldValueState: MutableState = remember { mutableStateOf(TextFieldValue()) }, chips: List = remember { emptyList() }, @@ -122,6 +124,7 @@ fun ChipTextField( ChipTextField( modifier = modifier, label = label, + trailingIcon = trailingIcon, textStyle = textStyle, textFieldValueState = textFieldValueState, chips = chips, @@ -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. @@ -160,6 +164,7 @@ fun ChipTextField( fun ChipTextField( modifier: Modifier = Modifier, label: @Composable (() -> Unit)? = null, + trailingIcon: @Composable (() -> Unit)? = null, textStyle: TextStyle = TextStyle.Default, textFieldValueState: MutableState = remember { mutableStateOf(TextFieldValue()) }, chips: List = remember { emptyList() }, @@ -189,6 +194,7 @@ fun ChipTextField( ) { TextFieldDefaults.DecorationBox( label = label, + trailingIcon = trailingIcon, value = textFieldValueState.value.text + if (chips.isNotEmpty()) " " else "", innerTextField = { FlowRow( diff --git a/presentation/components/src/commonMain/kotlin/com/shifthackz/aisdv1/presentation/components/widget/input/chip/ChipTextFieldWithItem.kt b/presentation/components/src/commonMain/kotlin/com/shifthackz/aisdv1/presentation/components/widget/input/chip/ChipTextFieldWithItem.kt index bbc657f7e..a2f737160 100644 --- a/presentation/components/src/commonMain/kotlin/com/shifthackz/aisdv1/presentation/components/widget/input/chip/ChipTextFieldWithItem.kt +++ b/presentation/components/src/commonMain/kotlin/com/shifthackz/aisdv1/presentation/components/widget/input/chip/ChipTextFieldWithItem.kt @@ -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 @@ -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. @@ -30,14 +32,16 @@ fun ChipTextFieldWithItem( textFieldValueState: MutableState, label: UiText, list: List, + trailingIcon: @Composable (() -> Unit)? = null, onItemClick: (type: Int, item: String) -> Unit = { _, _ -> }, onEvent: (event: ChipTextFieldEvent) -> 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), diff --git a/presentation/generation/src/commonMain/kotlin/com/shifthackz/aisdv1/presentation/generation/widget/input/GenerationPromptEditor.kt b/presentation/generation/src/commonMain/kotlin/com/shifthackz/aisdv1/presentation/generation/widget/input/GenerationPromptEditor.kt index 205e69e6b..1fb804ab5 100644 --- a/presentation/generation/src/commonMain/kotlin/com/shifthackz/aisdv1/presentation/generation/widget/input/GenerationPromptEditor.kt +++ b/presentation/generation/src/commonMain/kotlin/com/shifthackz/aisdv1/presentation/generation/widget/input/GenerationPromptEditor.kt @@ -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 @@ -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. @@ -50,12 +54,29 @@ 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)) }, @@ -63,8 +84,9 @@ internal fun GenerationPromptEditor( } 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,