Skip to content

The agent that grows with you

style: align canonical group controls with Desktop lint rules

Tekniumc8d8900dcd17
diff --git a/apps/desktop/src/i18n/canonical-group-labels.test.ts b/apps/desktop/src/i18n/canonical-group-labels.test.ts
index e76a4c79221..d555a5a5698 100644
--- a/apps/desktop/src/i18n/canonical-group-labels.test.ts
+++ b/apps/desktop/src/i18n/canonical-group-labels.test.ts
@@ -17,6 +17,7 @@ vi.mock('../plugins/hermes-bots/shared', () => ({ getPluginCtx: () => null }))
import { useCanonicalGroupLabels } from '../plugins/hermes-bots/canonical-group-labels'
import { BOTS_LOCALES } from '../plugins/hermes-bots/i18n'
+
import { TRANSLATIONS } from './catalog'
it('provides translated canonical group controls and recovery copy in every supported locale', () => {
@@ -35,10 +36,12 @@ it('provides translated canonical group controls and recovery copy in every supp
for (const [key, value] of Object.entries(messages!)) {
expect(result.current[key as keyof typeof result.current]).toBe(value)
expect(value.trim(), `${locale}.${key}`).not.toBe('')
+
if (locale !== 'en') {
expect(value, `${locale}.${key}`).not.toBe(english![key])
}
}
+
unmount()
}
})
diff --git a/apps/desktop/src/plugins/hermes-bots/canonical-group-attachments.tsx b/apps/desktop/src/plugins/hermes-bots/canonical-group-attachments.tsx
index ab1fe0c89ce..e96ec84377f 100644
--- a/apps/desktop/src/plugins/hermes-bots/canonical-group-attachments.tsx
+++ b/apps/desktop/src/plugins/hermes-bots/canonical-group-attachments.tsx
@@ -2,20 +2,24 @@ import { Button } from '@hermes/plugin-sdk'
import { useRef, useState } from 'react'
import { useCanonicalGroupLabels } from './canonical-group-labels'
-import { canonicalGroupRequest, type CanonicalGroupBinding } from './canonical-groups'
+import { type CanonicalGroupBinding, canonicalGroupRequest } from './canonical-groups'
interface Attachment { attachment_id?: string; event_id?: string; kind: string; name: string; mime: string; size?: number }
interface DownloadedAttachment extends Attachment { data_base64: string }
function kindFor(file: File): string {
- if (file.type.startsWith('image/')) return 'image'
- if (file.type === 'application/pdf') return 'pdf'
+ if (file.type.startsWith('image/')) {return 'image'}
+
+ if (file.type === 'application/pdf') {return 'pdf'}
+
return 'file'
}
function extension(mime: string, name: string): string {
const dot = name.lastIndexOf('.')
- if (dot > 0) return name.slice(dot)
+
+ if (dot > 0) {return name.slice(dot)}
+
return mime === 'application/pdf' ? '.pdf' : mime.split('/')[1] ? `.${mime.split('/')[1]}` : '.bin'
}
@@ -32,24 +36,29 @@ export function CanonicalGroupAttachments({ binding, attachments, onChange, disa
async function upload(file: File) {
setBusy(true); setError('')
+
try {
const data = await file.arrayBuffer()
+
const result = await canonicalGroupRequest<Attachment>(binding, 'bot.group.attachment.upload', {
room_id: binding.roomId, upload_id: crypto.randomUUID(), kind: kindFor(file), name: file.name,
mime: file.type || 'application/octet-stream', data_base64: btoa(String.fromCharCode(...new Uint8Array(data)))
})
+
onChange([...attachments, result])
} catch (e) { setError(e instanceof Error ? e.message : String(e)) }
finally { setBusy(false) }
}
async function download(attachment: Attachment) {
- if (!attachment.attachment_id || !attachment.event_id || !window.hermesDesktop?.saveImageBuffer) return
+ if (!attachment.attachment_id || !attachment.event_id || !window.hermesDesktop?.saveImageBuffer) {return}
setBusy(true); setError('')
+
try {
const result = await canonicalGroupRequest<DownloadedAttachment>(binding, 'bot.group.attachment.download', {
room_id: binding.roomId, event_id: attachment.event_id, attachment_id: attachment.attachment_id
})
+
const bytes = Uint8Array.from(atob(result.data_base64), char => char.charCodeAt(0))
await window.hermesDesktop.saveImageBuffer(bytes, extension(result.mime, result.name), result.name)
} catch (e) { setError(e instanceof Error ? e.message : String(e)) }
@@ -57,9 +66,11 @@ export function CanonicalGroupAttachments({ binding, attachments, onChange, disa
}
return <div className="flex flex-wrap items-center gap-2">
- <input ref={input} hidden type="file" onChange={e => { const file = e.target.files?.[0]; if (file) void upload(file); e.currentTarget.value = '' }} />
+ <input hidden onChange={e => { const file = e.target.files?.[0];
+
+ if (file) {void upload(file);} e.currentTarget.value = '' }} ref={input} type="file" />
<Button disabled={disabled || busy} onClick={() => input.current?.click()}>{labels.attachFiles}</Button>
- {attachments.map(a => <span key={a.attachment_id ?? a.name} className="flex items-center gap-1">
+ {attachments.map(a => <span className="flex items-center gap-1" key={a.attachment_id ?? a.name}>
<span>{a.name}</span><Button disabled={disabled || busy} onClick={() => void download(a)}>{labels.download}</Button>
<Button disabled={disabled || busy} onClick={() => onChange(attachments.filter(item => item !== a))}>{labels.removeAttachment}</Button>
</span>)}
diff --git a/apps/desktop/src/plugins/hermes-bots/canonical-group-workspace.tsx b/apps/desktop/src/plugins/hermes-bots/canonical-group-workspace.tsx
index 6f951e0b37e..01decf3d208 100644
--- a/apps/desktop/src/plugins/hermes-bots/canonical-group-workspace.tsx
+++ b/apps/desktop/src/plugins/hermes-bots/canonical-group-workspace.tsx
@@ -1,9 +1,9 @@
import { Button } from '@hermes/plugin-sdk'
import { useEffect, useRef, useState } from 'react'
+import { CanonicalGroupAttachments } from './canonical-group-attachments'
import { useCanonicalGroupLabels } from './canonical-group-labels'
import { prepareCanonicalGroupSend, readCanonicalGroupSend, retireCanonicalGroupSend } from './canonical-group-send'
-import { CanonicalGroupAttachments } from './canonical-group-attachments'
import type { PreparedCanonicalGroupSend } from './canonical-group-send'
import { actCanonicalGroup, canonicalGroupRequest } from './canonical-groups'
import type { CanonicalGroupBinding, CanonicalPendingAction } from './canonical-groups'
@@ -160,7 +160,7 @@ function CanonicalRoomView({ binding: initialBinding, visible, onBack }: {
</div>}
{pending && <p role="status">{labels.restoredPendingSend}</p>}
<form className="flex gap-2" onSubmit={event => { event.preventDefault(); send() }}>
- <CanonicalGroupAttachments binding={binding} attachments={attachments} onChange={setAttachments} disabled={!restored || busy || !!pending} />
+ <CanonicalGroupAttachments attachments={attachments} binding={binding} disabled={!restored || busy || !!pending} onChange={setAttachments} />
<textarea aria-label={labels.groupMessage} className="min-w-0 flex-1" disabled={!restored || busy || !!pending} onChange={e => setDraft(e.target.value)} value={draft} />
<Button disabled={!restored || busy || (!pending && !draft.trim() && !attachments.length) || !state?.driver_status} type="submit">{pending ? labels.retry : labels.send}</Button>
</form>