fix: BUG-009/010/011 — DataMasking, cancel button, SQL casts
Some checks failed
CI / Lint & TypeCheck (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Build Frontend (push) Has been cancelled
CI / Rust Check (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled
Some checks failed
CI / Lint & TypeCheck (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Build Frontend (push) Has been cancelled
CI / Rust Check (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled
BUG-009 (P1): Add frontend DataMasking in saas-relay-client.ts - Masks ID cards, phones, emails, money, company names before relay - Unmasks tokens in AI response so user sees original data - Mirrors Rust DataMasking middleware patterns BUG-010 (P3): Send button transforms to Stop during streaming - Shows square icon when isStreaming, calls cancelStream() - Normal arrow icon when idle, calls handleSend() BUG-011 (P2): Add ::timestamptz casts for old TEXT timestamp columns - account/handlers.rs: dashboard stats query - telemetry/service.rs: reported_at comparisons - workers/aggregate_usage.rs: usage aggregation query
This commit is contained in:
@@ -10,7 +10,7 @@ import { useConfigStore } from '../store/configStore';
|
||||
import { useSaaSStore } from '../store/saasStore';
|
||||
import { type UnlistenFn } from '@tauri-apps/api/event';
|
||||
import { safeListenEvent } from '../lib/safe-tauri';
|
||||
import { Paperclip, ArrowUp, MessageSquare, Download, X, FileText, Image as ImageIcon, Search, ClipboardList } from 'lucide-react';
|
||||
import { Paperclip, ArrowUp, MessageSquare, Download, X, FileText, Image as ImageIcon, Search, ClipboardList, Square } from 'lucide-react';
|
||||
import { Button, EmptyState, MessageListSkeleton, LoadingDots } from './ui';
|
||||
import { ResizableChatLayout } from './ai/ResizableChatLayout';
|
||||
import { ArtifactPanel } from './ai/ArtifactPanel';
|
||||
@@ -56,6 +56,7 @@ export function ChatArea({ compact, onOpenDetail }: { compact?: boolean; onOpenD
|
||||
sendMessage: sendToGateway, initStreamListener,
|
||||
chatMode, setChatMode, suggestions,
|
||||
totalInputTokens, totalOutputTokens,
|
||||
cancelStream,
|
||||
} = useChatStore();
|
||||
const currentAgent = useConversationStore((s) => s.currentAgent);
|
||||
const currentModel = useConversationStore((s) => s.currentModel);
|
||||
@@ -571,16 +572,28 @@ export function ChatArea({ compact, onOpenDetail }: { compact?: boolean; onOpenD
|
||||
disabled={isStreaming}
|
||||
/>
|
||||
)}
|
||||
<Button
|
||||
variant="primary"
|
||||
size="sm"
|
||||
onClick={handleSend}
|
||||
disabled={isStreaming || (!input.trim() && pendingFiles.length === 0)}
|
||||
className="w-8 h-8 rounded-full p-0 flex items-center justify-center bg-orange-500 hover:bg-orange-600 text-white disabled:opacity-50"
|
||||
aria-label="发送消息"
|
||||
>
|
||||
<ArrowUp className="w-4 h-4 text-white" />
|
||||
</Button>
|
||||
{isStreaming ? (
|
||||
<Button
|
||||
variant="primary"
|
||||
size="sm"
|
||||
onClick={cancelStream}
|
||||
className="w-8 h-8 rounded-full p-0 flex items-center justify-center bg-gray-500 hover:bg-gray-600 text-white"
|
||||
aria-label="停止生成"
|
||||
>
|
||||
<Square className="w-3.5 h-3.5 text-white fill-white" />
|
||||
</Button>
|
||||
) : (
|
||||
<Button
|
||||
variant="primary"
|
||||
size="sm"
|
||||
onClick={handleSend}
|
||||
disabled={!input.trim() && pendingFiles.length === 0}
|
||||
className="w-8 h-8 rounded-full p-0 flex items-center justify-center bg-orange-500 hover:bg-orange-600 text-white disabled:opacity-50"
|
||||
aria-label="发送消息"
|
||||
>
|
||||
<ArrowUp className="w-4 h-4 text-white" />
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -16,6 +16,57 @@ import { createLogger } from './logger';
|
||||
|
||||
const log = createLogger('SaaSRelayGateway');
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Frontend DataMasking — mirrors Rust DataMasking middleware for SaaS Relay
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
const MASK_PATTERNS: RegExp[] = [
|
||||
/\b\d{17}[\dXx]\b/g, // ID card
|
||||
/1[3-9]\d-?\d{4}-?\d{4}/g, // Phone
|
||||
/[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/g, // Email
|
||||
/[¥¥$]\s*[\d,.]+[万亿]?元?|[\d,.]+[万亿]元/g, // Money
|
||||
/[^\s]{1,20}(?:公司|厂|集团|工作室|商行|有限|股份)/g, // Company
|
||||
];
|
||||
|
||||
let maskCounter = 0;
|
||||
const entityMap = new Map<string, string>();
|
||||
|
||||
/** Mask sensitive entities in text before sending to SaaS relay. */
|
||||
function maskSensitiveData(text: string): string {
|
||||
const entities: { text: string; token: string }[] = [];
|
||||
|
||||
for (const pattern of MASK_PATTERNS) {
|
||||
pattern.lastIndex = 0;
|
||||
let match: RegExpExecArray | null;
|
||||
while ((match = pattern.exec(text)) !== null) {
|
||||
const entity = match[0];
|
||||
if (!entityMap.has(entity)) {
|
||||
maskCounter++;
|
||||
entityMap.set(entity, `__ENTITY_${maskCounter}__`);
|
||||
}
|
||||
entities.push({ text: entity, token: entityMap.get(entity)! });
|
||||
}
|
||||
}
|
||||
|
||||
// Sort by length descending to replace longest entities first
|
||||
entities.sort((a, b) => b.text.length - a.text.length);
|
||||
|
||||
let result = text;
|
||||
for (const { text: entity, token } of entities) {
|
||||
result = result.split(entity).join(token);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/** Restore masked tokens in AI response back to original entities. */
|
||||
function unmaskSensitiveData(text: string): string {
|
||||
let result = text;
|
||||
for (const [entity, token] of entityMap) {
|
||||
result = result.split(token).join(entity);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Types
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -122,10 +173,12 @@ export function createSaaSRelayGatewayClient(
|
||||
|
||||
try {
|
||||
// Build messages array: use history if available, fallback to current message only
|
||||
// Apply DataMasking to protect sensitive data before sending to relay
|
||||
const history = opts?.history || [];
|
||||
const maskedMessage = maskSensitiveData(message);
|
||||
const messages = history.length > 0
|
||||
? [...history, { role: 'user' as const, content: message }]
|
||||
: [{ role: 'user' as const, content: message }];
|
||||
? [...history, { role: 'user' as const, content: maskedMessage }]
|
||||
: [{ role: 'user' as const, content: maskedMessage }];
|
||||
|
||||
const body: Record<string, unknown> = {
|
||||
model: getModel() || 'glm-4-flash-250414',
|
||||
@@ -205,9 +258,9 @@ export function createSaaSRelayGatewayClient(
|
||||
callbacks.onThinkingDelta?.(delta.reasoning_content);
|
||||
}
|
||||
|
||||
// Handle regular content
|
||||
// Handle regular content — unmask tokens so user sees original entities
|
||||
if (delta?.content) {
|
||||
callbacks.onDelta(delta.content);
|
||||
callbacks.onDelta(unmaskSensitiveData(delta.content));
|
||||
}
|
||||
|
||||
// Check for completion
|
||||
|
||||
Reference in New Issue
Block a user