feat(cortex): update chat/nudge flow, deepgram streaming and agenda form

Refines chat panel, nudge messages and artifact rendering, reworks
deepgram token/streaming handling, and adds test tooling deps
(playwright, cypress) to package.json.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
colinislit
2026-07-09 22:37:46 +02:00
parent 6c6dae5eb7
commit cdeea793bd
20 changed files with 1634 additions and 283 deletions

View File

@@ -24,6 +24,16 @@ export type Patient = Database['public']['Tables']['patients']['Row'];
// Store-specific types (not in lib/cortex/types.ts)
export type BlockType = Exclude<CortexIntent, 'unknown'> | 'fallback' | 'patient-dashboard';
// No-show flow state machine
export type NoShowStep = 'idle' | 'waiting_cancel' | 'waiting_brief' | 'brief_open' | 'done';
export interface NoShowFlowState {
step: NoShowStep;
appointmentId: string | null;
documentId: string | null;
originalContent: string | null;
}
// Chat entities - simplified version for AI responses (strings, not Dates)
// This differs from ExtractedEntities in lib/cortex/types.ts which uses Date objects
// All properties are optional to match Zod schema flexibility
@@ -79,8 +89,9 @@ export interface ChatAction {
}
// Block prefill data - uses ChatEntities (string-based) for UI prefilling
// Index signature allows block-specific extra fields (e.g. documentId for NoShowDocumentBlock)
export interface BlockPrefillData extends ChatEntities {
// Additional prefill data specific to blocks
[key: string]: unknown;
}
// Artifact type (E4 - Multiple artifacts support)
@@ -145,6 +156,10 @@ interface CortexStore {
// V2 Clarification state
pendingClarification: ClarificationRequest | null;
// No-show flow state
noShowFlow: NoShowFlowState;
isNoShowProcessing: boolean;
// Context actions
setActivePatient: (patient: Patient | null) => void;
setShift: (shift: ShiftType) => void;
@@ -202,6 +217,12 @@ interface CortexStore {
setPendingClarification: (clarification: ClarificationRequest | null) => void;
resolveClarification: (selectedOption: string) => void;
// No-show flow actions
setNoShowStep: (step: NoShowStep) => void;
setNoShowContext: (ctx: Partial<Omit<NoShowFlowState, 'step'>>) => void;
setNoShowProcessing: (processing: boolean) => void;
resetNoShowFlow: () => void;
// Reset
reset: () => void;
}
@@ -233,6 +254,14 @@ const initialState = {
chainHistory: [] as IntentChain[],
suggestions: [] as NudgeSuggestion[],
pendingClarification: null as ClarificationRequest | null,
// No-show flow state
noShowFlow: {
step: 'idle',
appointmentId: null,
documentId: null,
originalContent: null,
} as NoShowFlowState,
isNoShowProcessing: false,
};
// Create the store
@@ -576,6 +605,39 @@ export const useCortexStore = create<CortexStore>()(
'resolveClarification'
),
// No-show flow actions
setNoShowStep: (step) =>
set(
(state) => ({ noShowFlow: { ...state.noShowFlow, step } }),
false,
'setNoShowStep'
),
setNoShowContext: (ctx) =>
set(
(state) => ({ noShowFlow: { ...state.noShowFlow, ...ctx } }),
false,
'setNoShowContext'
),
setNoShowProcessing: (processing) =>
set({ isNoShowProcessing: processing }, false, 'setNoShowProcessing'),
resetNoShowFlow: () =>
set(
{
noShowFlow: {
step: 'idle',
appointmentId: null,
documentId: null,
originalContent: null,
},
isNoShowProcessing: false,
},
false,
'resetNoShowFlow'
),
// Reset
reset: () => set(initialState, false, 'reset'),
}),