feat(desktop): sync knowledge, recordings and shared settings; play any recording

Knowledge documents travel as source-text chunks; each surface embeds them
with its own model, the server index is requested through embed-chunks, and
documents from the phone are stored without a file and indexed from their
chunks. Chunk text is now kept when local embedding fails, so reindexing no
longer needs the original file.

Recordings upload to the mobile storage contract (audio bucket under the
user's folder plus an audio_files row, 50 MiB cap, a Settings > Cloud
toggle) and are removed with their record. The history card gains a play
button that uses the local file or, for phone recordings, a signed URL.

Language (ko/en), system/light/dark theme, auto-polish and the active user
command follow the phone's user_settings with its revision rule; changes that
arrive from the phone reach the open window.
This commit is contained in:
Yun Chan 2026-09-27 14:44:56 +09:00
parent cee4ab9317
commit 9a8f7e6aa6
34 changed files with 1405 additions and 64 deletions

View file

@ -13,7 +13,7 @@ import {
type RealtimeChannel
} from '@supabase/supabase-js'
import { getLogger } from './LoggerService'
import { configGet, configSet } from './ConfigService'
import { configGet, configSet, onConfigChanged } from './ConfigService'
import { SUPABASE_URL, SUPABASE_ANON_KEY } from '@d3ro/core/supabase-config'
import { openForUser, openLocal, closeCurrent, getCurrentUserId, importLocalModeData } from '../db'
import { D3ROError, ErrorCode } from '@d3ro/core/errors'
@ -24,6 +24,8 @@ import { enqueueChange, getSyncState, setSyncState } from './sync/sync-outbox'
import { checkInDesktopDevice, currentDeviceInfo, unregisterDesktopDevice } from './sync/device-registration'
import type { SyncEntity, SyncRunResult } from './sync/sync-types'
import { nodeRealtimeTransport } from './sync/realtime-transport'
import { SETTINGS_ROW_ID, SYNCED_CONFIG_KEYS, isApplyingRemoteSettings } from './sync/settings-sync'
import { AUDIO_BUCKET, listLocalAudioOwners } from './sync/audio-sync'
const logger = getLogger('CloudSyncService')
@ -46,6 +48,8 @@ const REALTIME_TABLES = [
'memo_tags',
'custom_instructions',
'user_templates',
'knowledge_documents',
'user_settings',
'sync_tombstones',
] as const
@ -125,6 +129,23 @@ class CloudSyncService extends EventEmitter {
this._lastSyncAt = (configGet('cloudSyncLastAt') as number | undefined) ?? null
// 언어·테마·자동 다듬기·활성 명령이 바뀌면 모바일 user_settings 로 올린다(원격 반영 중엔 제외).
onConfigChanged((event) => {
if (isApplyingRemoteSettings()) return
if ((SYNCED_CONFIG_KEYS as readonly string[]).includes(event.key)) {
this.pushOne('user_settings', SETTINGS_ROW_ID)
}
// 녹음 동기화를 켜면 그동안 올리지 않은 녹음을 올린다.
if (event.key === 'cloudSyncAudio' && event.value === true && this._engine) {
try {
for (const id of listLocalAudioOwners('history')) this.pushOne('history_audio', id)
for (const id of listLocalAudioOwners('meeting')) this.pushOne('meeting_audio', id)
} catch (err) {
logger.warn(`Audio re-queue failed: ${err instanceof Error ? err.message : String(err)}`)
}
}
})
// 저장된 refresh token 복원
const stored = this._loadStoredRefreshToken()
if (stored) {
@ -913,6 +934,29 @@ class CloudSyncService extends EventEmitter {
}
}
/**
* 다른 기기(모바일·웹)에서 녹음한 기록의 재생 URL(5분 서명). 로컬 파일이 없을 때만 쓴다.
* 로그인 전이거나 서버에 녹음이 없으면 null.
*/
async createHistoryAudioUrl(historyId: string): Promise<string | null> {
const client = this._client
const session = this._session
if (!client || !session) return null
const { data, error } = await client
.from('audio_files')
.select('storage_key,upload_status')
.eq('user_id', session.user.id)
.eq('history_id', historyId)
.eq('upload_status', 'uploaded')
.order('created_at', { ascending: false })
.limit(1)
.maybeSingle()
if (error || !data || typeof data.storage_key !== 'string') return null
if (!data.storage_key.startsWith(`${session.user.id}/`)) return null
const signed = await client.storage.from(AUDIO_BUCKET).createSignedUrl(data.storage_key, 300)
return signed.error ? null : signed.data.signedUrl
}
getSyncStatus(): SyncStatus | null {
if (!this._engine) return null
try {