mirror of
https://github.com/temetro/temetro.git
synced 2026-07-26 11:58:14 +00:00
929bec8f31
Stop blocking AI imports/proposals on missing non-critical fields. Records the chat agent drafts now save with safe placeholders, auto-generated file numbers, and a source="ai" marker that surfaces an "Added by AI" badge so a clinician can review/edit them later. Backend: - add `source` (manual|ai) column to patients/appointments/prescriptions (migration 0014) + canonical types, services, validation schemas - relax patient/appointment validation: empty file number allowed, demographic + type/provider/initials fall back to placeholders (initials derived from name) - patients.generateFileNumber() auto-assigns an MRN when one is missing - proposeAppointment accepts a name when no file number resolves; AI commits + /api/ai/import stamp source="ai" Frontend: - `source` on Appointment/Patient/Prescription types; AI commits send source="ai" - reusable <AiBadge> shown on the Patients table/detail and prescriptions list Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
72 lines
2.2 KiB
TypeScript
72 lines
2.2 KiB
TypeScript
"use client";
|
|
|
|
import {
|
|
Reasoning,
|
|
ReasoningContent,
|
|
ReasoningTrigger,
|
|
} from "@/components/ai-elements/reasoning";
|
|
import { useCallback, useEffect, useState } from "react";
|
|
|
|
const reasoningSteps = [
|
|
"Let me think about this problem step by step.",
|
|
"\n\nFirst, I need to understand what the user is asking for.",
|
|
"\n\nThey want a reasoning component that opens automatically when streaming begins and closes when streaming finishes. The component should be composable and follow existing patterns in the codebase.",
|
|
"\n\nThis seems like a collapsible component with state management would be the right approach.",
|
|
].join("");
|
|
|
|
const Example = () => {
|
|
const [content, setContent] = useState("");
|
|
const [isStreaming, setIsStreaming] = useState(false);
|
|
const [currentTokenIndex, setCurrentTokenIndex] = useState(0);
|
|
const [tokens, setTokens] = useState<string[]>([]);
|
|
|
|
// Function to chunk text into fake tokens of 3-4 characters
|
|
const chunkIntoTokens = useCallback((text: string): string[] => {
|
|
const chunks: string[] = [];
|
|
let i = 0;
|
|
while (i < text.length) {
|
|
// Random size between 3-4
|
|
const chunkSize = Math.floor(Math.random() * 2) + 3;
|
|
chunks.push(text.slice(i, i + chunkSize));
|
|
i += chunkSize;
|
|
}
|
|
return chunks;
|
|
}, []);
|
|
|
|
useEffect(() => {
|
|
const tokenizedSteps = chunkIntoTokens(reasoningSteps);
|
|
setTokens(tokenizedSteps);
|
|
setContent("");
|
|
setCurrentTokenIndex(0);
|
|
setIsStreaming(true);
|
|
}, [chunkIntoTokens]);
|
|
|
|
useEffect(() => {
|
|
if (!isStreaming || currentTokenIndex >= tokens.length) {
|
|
if (isStreaming) {
|
|
setIsStreaming(false);
|
|
}
|
|
return;
|
|
}
|
|
|
|
// Faster interval since we're streaming smaller chunks
|
|
const timer = setTimeout(() => {
|
|
setContent((prev) => prev + tokens[currentTokenIndex]);
|
|
setCurrentTokenIndex((prev) => prev + 1);
|
|
}, 25);
|
|
|
|
return () => clearTimeout(timer);
|
|
}, [isStreaming, currentTokenIndex, tokens]);
|
|
|
|
return (
|
|
<div className="w-full p-4" style={{ height: "300px" }}>
|
|
<Reasoning className="w-full" isStreaming={isStreaming}>
|
|
<ReasoningTrigger />
|
|
<ReasoningContent>{content}</ReasoningContent>
|
|
</Reasoning>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default Example;
|