feat: expand companion platform, device controls, and memoir workflows
ci / verify (push) Canceled after 0s

Add customer and operator login, BLE provisioning, device fleet controls, call memory, memoir generation, and refreshed family and maintenance portals. Include API contracts, migrations, firmware sources, tests, assets, and deployment documentation.
This commit is contained in:
Codex Local
2026-10-08 10:06:44 +08:00
parent 98fb2965d0
commit bf1233d5df
861 changed files with 94614 additions and 3209 deletions
+24 -4
View File
@@ -88,6 +88,7 @@ type usageOverviewRow struct {
costMicros int64
currency string
hasCost bool
isCallSession bool
}
func (s *Service) FamilyUsageOverview(ctx context.Context, principal identity.Principal, householdPublicID, devicePublicID, timezone string, from, to time.Time) (UsageOverview, error) {
@@ -158,6 +159,8 @@ func (s *Service) resolveUsageOverviewDevice(ctx context.Context, target *usageO
query += ` AND (
EXISTS(SELECT 1 FROM device_binding b WHERE b.tenant_id=d.tenant_id AND b.device_id=d.id AND b.household_id=$3::uuid AND b.unbound_at IS NULL)
OR EXISTS(SELECT 1 FROM conversation c WHERE c.tenant_id=d.tenant_id AND c.device_id=d.id AND c.household_id=$3::uuid)
OR EXISTS(SELECT 1 FROM call_session c JOIN subject_profile sp ON sp.id=c.subject_id AND sp.tenant_id=c.tenant_id
WHERE c.tenant_id=d.tenant_id AND c.device_id=d.id AND sp.household_id=$3::uuid)
)`
args = append(args, target.householdID)
}
@@ -179,8 +182,8 @@ func (s *Service) buildUsageOverview(ctx context.Context, target usageOverviewTa
from = from.UTC()
to = to.UTC()
rows, err := s.pool.Query(ctx, `
SELECT c.public_id::text,h.public_id::text,h.name,d.public_id::text,d.model,sp.preferred_name,c.status,c.started_at,c.ended_at,
COALESCE(cost.cost_micros,0)::bigint,COALESCE(cost.currency,''),COALESCE(cost.has_cost,false)
SELECT c.public_id::text AS conversation_id,h.public_id::text,h.name,d.public_id::text,d.model,sp.preferred_name,c.status,c.started_at,c.ended_at,
COALESCE(cost.cost_micros,0)::bigint,COALESCE(cost.currency,''),COALESCE(cost.has_cost,false),false AS is_call_session
FROM conversation c
JOIN household h ON h.id=c.household_id AND h.tenant_id=c.tenant_id
JOIN device d ON d.id=c.device_id AND d.tenant_id=c.tenant_id
@@ -192,7 +195,19 @@ func (s *Service) buildUsageOverview(ctx context.Context, target usageOverviewTa
WHERE c.tenant_id=$1::uuid AND c.started_at IS NOT NULL AND c.started_at>=$2 AND c.started_at<$3
AND ($4::uuid IS NULL OR c.household_id=$4::uuid)
AND ($5::uuid IS NULL OR c.device_id=$5::uuid)
ORDER BY c.started_at DESC,c.public_id`, target.tenantID, from, to, nullableUUID(target.householdID), nullableUUID(target.deviceID))
UNION ALL
SELECT c.id::text,h.public_id::text,h.name,d.public_id::text,d.model,sp.preferred_name,
CASE c.call_state WHEN 'ENDED' THEN 'COMPLETED' WHEN 'TALKING' THEN 'ACTIVE'
WHEN 'CANCELLED' THEN 'FAILED' WHEN 'STARTING' THEN 'STARTING_AGENT' ELSE c.call_state END,
c.created_at,c.ended_at,0::bigint,''::text,false,true
FROM call_session c
JOIN subject_profile sp ON sp.id=c.subject_id AND sp.tenant_id=c.tenant_id
JOIN household h ON h.id=sp.household_id AND h.tenant_id=c.tenant_id
JOIN device d ON d.id=c.device_id AND d.tenant_id=c.tenant_id
WHERE c.tenant_id=$1::uuid AND c.created_at>=$2 AND c.created_at<$3
AND ($4::uuid IS NULL OR sp.household_id=$4::uuid)
AND ($5::uuid IS NULL OR c.device_id=$5::uuid)
ORDER BY started_at DESC,conversation_id`, target.tenantID, from, to, nullableUUID(target.householdID), nullableUUID(target.deviceID))
if err != nil {
return UsageOverview{}, err
}
@@ -210,10 +225,15 @@ func (s *Service) buildUsageOverview(ctx context.Context, target usageOverviewTa
today := time.Now().In(location).Format("2006-01-02")
for rows.Next() {
var row usageOverviewRow
if err = rows.Scan(&row.conversationID, &row.householdID, &row.householdName, &row.deviceID, &row.deviceName, &row.subjectName, &row.status, &row.startedAt, &row.endedAt, &row.costMicros, &row.currency, &row.hasCost); err != nil {
if err = rows.Scan(&row.conversationID, &row.householdID, &row.householdName, &row.deviceID, &row.deviceName, &row.subjectName, &row.status, &row.startedAt, &row.endedAt, &row.costMicros, &row.currency, &row.hasCost, &row.isCallSession); err != nil {
return UsageOverview{}, err
}
duration := conversationDurationMS(row.startedAt, row.endedAt, to)
// Match calls/query: a new session has no finalized duration until it ends.
// Do not inflate abandoned preparations or missing end reports up to now.
if row.isCallSession && row.endedAt == nil {
duration = 0
}
date := row.startedAt.In(location).Format("2006-01-02")
day := daily[date]
if day == nil {