Files
rhema-claw/web/claw/app/components/UserProfileModal.vue
T
vhaudiquet cb1948742f
android / debug (push) Successful in 2m26s
android / release (push) Successful in 2m19s
ci / checks (push) Successful in 3m48s
ci / test (push) Successful in 1m24s
ci / chart (push) Successful in 7s
ci / docker (push) Successful in 2m11s
ci / web (push) Successful in 15s
ci / publish-edge-images (deploy/docker/claw.Dockerfile, rhema-claw) (push) Successful in 2m17s
ci / publish-edge-images (deploy/docker/ui.Dockerfile, rhema-claw-ui) (push) Successful in 16s
ci / publish-edge-chart (push) Successful in 4s
feat(claw): show the user's profile in the bottom-left account
The web shell's account showed the agent's identity and the word
"connected", which left no way to see or set the human's own name and
picture.

The claw now stores a user profile beside the bootstrap files and
serves it over /v1/user and /v1/user/avatar. The agent sets it during
onboarding with user_profile_set; the bottom-left account in both
sidebars renders it and opens an editor for the name and picture. The
prompt context exposes user_name and user_profile, and bootstrap
documents resolve {{ user_name }}, so USER.md and the other markdown
files can address the user by name.

The connection state stays with the unreachable banner, so the sidebars
no longer report it.

Unit and HTTP tests cover the profile store, the tool, the variable
expansion, and the routes. fmt, clippy, cargo test, nuxt typecheck, and
nuxt build pass; both sidebars and the editor checked at 1280x800.
2026-12-01 18:30:50 +01:00

171 lines
4.1 KiB
Vue

<script setup lang="ts">
// The user-profile editor the bottom-left account opens: a display name
// and a picture. The name saves from the footer; the picture applies as
// soon as a file is chosen, the same immediate upload the agent's own
// avatar uses. Presentational: data in as props, intent out as events.
import { User } from 'lucide-vue-next'
import type { UserProfile } from '~/composables/useClaw'
const props = defineProps<{
open: boolean
profile: UserProfile | null
avatarUrl: string | null
/** A name save is in flight. */
saving: boolean
/** A picture upload or clear is in flight. */
mutating: boolean
}>()
const emit = defineEmits<{
close: []
save: [name: string]
uploadAvatar: [file: File]
clearAvatar: []
}>()
const draft = ref('')
const nameToken = '{{ user_name }}'
const initialized = ref(false)
const dirty = computed(() => draft.value.trim() !== (props.profile?.name ?? ''))
// The first profile arrival fills the draft; later ones only when the
// operator has not typed, so a background refresh never erases an edit.
watch(
() => props.profile,
(profile) => {
if (!profile || (initialized.value && dirty.value)) return
initialized.value = true
draft.value = profile.name ?? ''
},
{ immediate: true },
)
// Opening starts from the saved profile: a cancelled edit is gone the
// next time the modal opens.
watch(
() => props.open,
(open) => {
if (!open) return
draft.value = props.profile?.name ?? ''
initialized.value = true
},
)
const fileInput = ref<HTMLInputElement | null>(null)
function chooseFile(): void {
fileInput.value?.click()
}
function onFileChosen(event: Event): void {
const input = event.target as HTMLInputElement
const file = input.files?.[0]
if (file) emit('uploadAvatar', file)
input.value = ''
}
function save(): void {
if (!dirty.value || props.saving) return
emit('save', draft.value.trim())
}
</script>
<template>
<AppModal :open="open" title="Your profile" @close="$emit('close')">
<div class="identity">
<AgentAvatar
v-if="avatarUrl || draft.trim()"
:avatar-url="avatarUrl"
:initials="draft.trim().slice(0, 1)"
:size="48"
/>
<span v-else class="glyph" aria-hidden="true"><User :size="20" /></span>
<div class="image-control">
<button :disabled="mutating" @click="chooseFile">Upload picture…</button>
<button
v-if="profile?.avatar"
class="btn-quiet"
:disabled="mutating"
@click="$emit('clearAvatar')"
>
Remove
</button>
<input
ref="fileInput"
type="file"
accept="image/png,image/jpeg,image/gif,image/webp"
@change="onFileChosen"
>
</div>
</div>
<label class="field">
<span class="field-name">Display name</span>
<input
v-model="draft"
type="text"
maxlength="64"
placeholder="Your name"
autocomplete="off"
:disabled="saving"
@keydown.enter.prevent="save"
>
<span class="field-note">Shown on the account in the sidebar and readable as {{ nameToken }} by the agent's documents.</span>
</label>
<template #actions>
<button class="btn-quiet" :disabled="saving" @click="$emit('close')">Cancel</button>
<button :disabled="!dirty || saving" @click="save">
{{ saving ? 'Saving…' : 'Save' }}
</button>
</template>
</AppModal>
</template>
<style scoped>
.identity {
display: flex;
align-items: center;
gap: var(--sp-4);
margin-bottom: var(--sp-4);
}
.glyph {
display: grid;
place-items: center;
flex: none;
width: 48px;
height: 48px;
border-radius: var(--r-avatar);
background: var(--surface-2);
color: var(--muted);
}
.image-control {
display: flex;
align-items: center;
gap: var(--sp-2);
}
.image-control input[type='file'] {
display: none;
}
.field {
display: flex;
flex-direction: column;
gap: var(--sp-1);
}
.field-name {
color: var(--text);
font-size: var(--fs-ui);
font-weight: 500;
}
.field-note {
color: var(--muted);
font-size: var(--fs-small);
}
</style>