diff --git a/packages/i18n/src/locales/en/settings.yaml b/packages/i18n/src/locales/en/settings.yaml index 5cd1bdf4c..2f4f800f8 100644 --- a/packages/i18n/src/locales/en/settings.yaml +++ b/packages/i18n/src/locales/en/settings.yaml @@ -75,6 +75,7 @@ pages: active: Active active_badge: Currently Active cancel: Cancel action + save: Save changes card_not_found: Card not found character: Character close: Close @@ -89,6 +90,7 @@ pages: description_label: Description drop_here: Drop to upload create_card: Create a new Card + edit_card: Edit Card creation: identity: Identity name: Name diff --git a/packages/stage-pages/src/pages/settings/airi-card/components/CardCreationDialog.vue b/packages/stage-pages/src/pages/settings/airi-card/components/CardCreationDialog.vue index d64adc10c..ccbd4b33d 100644 --- a/packages/stage-pages/src/pages/settings/airi-card/components/CardCreationDialog.vue +++ b/packages/stage-pages/src/pages/settings/airi-card/components/CardCreationDialog.vue @@ -12,14 +12,15 @@ import { DialogRoot, DialogTitle, } from 'reka-ui' -import { computed, ref, toRaw } from 'vue' +import { computed, ref, toRaw, watch } from 'vue' import { useI18n } from 'vue-i18n' interface Props { modelValue: boolean + cardId?: string // If provided, edit mode; otherwise create mode } -defineProps() +const props = defineProps() const emit = defineEmits<{ (e: 'update:modelValue', value: boolean): void }>() @@ -29,6 +30,9 @@ const modelValue = defineModel() const { t } = useI18n() const cardStore = useAiriCardStore() +// Determine if we're in edit mode +const isEditMode = computed(() => !!props.cardId) + // Tab type definition interface Tab { id: string @@ -112,25 +116,53 @@ function saveCard(card: Card): boolean { } showError.value = false - cardStore.addCard(rawCard) + if (isEditMode.value && props.cardId) { + // Edit mode: update existing card + cardStore.updateCard(props.cardId, rawCard) + } + else { + // Create mode: add new card + cardStore.addCard(rawCard) + } + modelValue.value = false // Close this return true } // Cards data holders : -const card = ref({ - name: t('settings.pages.card.creation.defaults.name'), - nickname: undefined, - version: '1.0', - description: '', - notes: undefined, - personality: t('settings.pages.card.creation.defaults.personality'), - scenario: t('settings.pages.card.creation.defaults.scenario'), - systemPrompt: t('settings.pages.card.creation.defaults.systemprompt'), - postHistoryInstructions: t('settings.pages.card.creation.defaults.posthistoryinstructions'), - greetings: [], - messageExample: [], +// Initialize card data - load from existing card if in edit mode +function initializeCard(): Card { + if (isEditMode.value && props.cardId) { + const existingCard = cardStore.getCard(props.cardId) + if (existingCard) { + return { ...toRaw(existingCard) } + } + } + + // Default values for create mode + return { + name: t('settings.pages.card.creation.defaults.name'), + nickname: undefined, + version: '1.0', + description: '', + notes: undefined, + personality: t('settings.pages.card.creation.defaults.personality'), + scenario: t('settings.pages.card.creation.defaults.scenario'), + systemPrompt: t('settings.pages.card.creation.defaults.systemprompt'), + postHistoryInstructions: t('settings.pages.card.creation.defaults.posthistoryinstructions'), + greetings: [], + messageExample: [], + } +} + +const card = ref(initializeCard()) + +// Reinitialize when cardId changes or dialog opens +watch(() => [props.modelValue, props.cardId], () => { + if (props.modelValue) { + card.value = initializeCard() + } }) function makeComputed( @@ -179,7 +211,7 @@ const cardPostHistoryInstructions = makeComputed('postHistoryInstructions')
- {{ t("settings.pages.card.create_card") }} + {{ isEditMode ? t("settings.pages.card.edit_card") : t("settings.pages.card.create_card") }} @@ -255,7 +287,7 @@ const cardPostHistoryInstructions = makeComputed('postHistoryInstructions') +
+
+
diff --git a/packages/stage-pages/src/pages/settings/airi-card/index.vue b/packages/stage-pages/src/pages/settings/airi-card/index.vue index a303425a3..085dc64ef 100644 --- a/packages/stage-pages/src/pages/settings/airi-card/index.vue +++ b/packages/stage-pages/src/pages/settings/airi-card/index.vue @@ -22,6 +22,8 @@ const { cards, activeCardId } = storeToRefs(cardStore) // Currently selected card ID (different from active card ID) const selectedCardId = ref('') +// Currently editing card ID +const editingCardId = ref('') // Dialog state const isCardDialogOpen = ref(false) const isCardCreationDialogOpen = ref(false) @@ -116,11 +118,27 @@ function confirmDelete(id: string) { } function handleSelectCard(cardId: string) { + // Verify card exists before opening dialog + if (!cards.value.has(cardId)) { + console.error(`Card with id ${cardId} not found`) + return + } selectedCardId.value = cardId isCardDialogOpen.value = true } +function handleEditCard(cardId: string) { + // Verify card exists before opening edit dialog + if (!cards.value.has(cardId)) { + console.error(`Card with id ${cardId} not found`) + return + } + editingCardId.value = cardId + isCardCreationDialogOpen.value = true +} + function handleCardCreationDialog() { + editingCardId.value = '' // Clear editing state for new card creation isCardCreationDialogOpen.value = true } @@ -129,6 +147,13 @@ function activateCard(id: string) { activeCardId.value = id } +// Clear editing state when creation/edit dialog closes +watch(isCardCreationDialogOpen, (isOpen) => { + if (!isOpen) { + editingCardId.value = '' + } +}) + // Card version number function getVersionNumber(id: string) { const card = cards.value.get(id) @@ -241,6 +266,7 @@ function getModuleShortName(id: string, module: 'consciousness' | 'voice') { @select="handleSelectCard(item.id)" @activate="activateCard(item.id)" @delete="confirmDelete(item.id)" + @edit="handleEditCard(item.id)" /> @@ -281,9 +307,10 @@ function getModuleShortName(id: string, module: 'consciousness' | 'voice') { :card-id="selectedCardId" /> - + diff --git a/packages/stage-ui/src/stores/modules/airi-card.ts b/packages/stage-ui/src/stores/modules/airi-card.ts index 37f1b9123..5c2820d0b 100644 --- a/packages/stage-ui/src/stores/modules/airi-card.ts +++ b/packages/stage-ui/src/stores/modules/airi-card.ts @@ -84,6 +84,20 @@ export const useAiriCardStore = defineStore('airi-card', () => { cards.value.delete(id) } + const updateCard = (id: string, updates: AiriCard | Card | ccv3.CharacterCardV3) => { + const existingCard = cards.value.get(id) + if (!existingCard) + return false + + const updatedCard = { + ...existingCard, + ...updates, + } + + cards.value.set(id, newAiriCard(updatedCard)) + return true + } + const getCard = (id: string) => { return cards.value.get(id) } @@ -223,6 +237,7 @@ export const useAiriCardStore = defineStore('airi-card', () => { activeCardId, addCard, removeCard, + updateCard, getCard, resetState, initialize,