Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions docs/aadi-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,28 @@ under `AADI_DATA_POLICY=openai-standard-retention` and input must carry no patie
packaging does not add production authentication or establish clinical accuracy.
Historical inference timings predate this packaging change. See the dated
verification report for fresh install/build/run evidence and remaining limits.

## Analysis progress

Since 2026-11-26 (Gaffer: "A + B: tahap nyata + reveal halus") the workspace shows the gateway's real stages while an
analysis runs. Model text is deliberately not streamed: the engine returns one structured result per step, and the
gateway and then the browser validate it and run the dose evidence gate before anything is shown. Streaming text
would put unvalidated, ungated doses on screen.

- Opt-in: the workspace sends `Accept: application/x-ndjson, application/json` to `POST /api/aadi`. Without that
header the reply is unchanged.
- Streamed reply: status 200, `Content-Type: application/x-ndjson`, `Cache-Control: no-store, no-transform`,
`X-Accel-Buffering: no`; one JSON object per line.
- `{"type":"stage","stage":S,"state":"running"|"done"|"failed"}`, S one of `retrieve_dx`, `aadi_dx`, `retrieve_tx`,
`aadi_tx`, `gate`. Nothing else: no case text, output, cost, error codes or timings.
- Last line `{"type":"final","status":N,"body":B}`: exactly the status and body the plain reply would carry,
refusals included. The browser validates and gates B as before.
- Code: `src/lib/aadi/stage-stream.ts` (writer and reader), `step(request, principal, onStage)` in
`src/lib/aadi/gateway.ts`, wait card `src/components/thinking-card.tsx`. Tests: `tests/aadi-stage-stream.test.ts`,
`tests/ui/thinking-card.test.tsx`.
- Not yet verified: that Cloudflare Access in front of the beta server passes the lines through as they are written.
If it buffers, all stage lines arrive with the answer and the card behaves as before.

On arrival the answer and the document pane come in through one view transition (`smooth(update, "arrive")`): the chat
column, composer and header tools glide to their new width, and the analysis's sections rise in 60 ms apart. A fresh
answer is scrolled to its top. Under reduced motion everything appears at once (`tests/ui/answer-arrival.test.tsx`).
2 changes: 1 addition & 1 deletion docs/sentrapedia-ui.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ Terapi Farmakologi: "Untuk <diagnosis> (<kode>)", satu obat per baris dengan dos

## Workspace berbentuk Glass (2026-11-04)

Menggantikan Clinical Cockpit, rail "Alur kasus", jawaban diketik, dan dialog Pengaturan Agent di atas. Sidebar mengikuti urutan Glass; kanvas terbagi antara chat dan panel dokumen di atas 1200 px (sheet "Dokumen encounter" di bawahnya). Chat berisi prosa, ringkasan dokter, dan kartu dokumen; panel berisi tab Ringkasan encounter dan satu tab per dokumen. Analisis AADI dirender dari hasil mesin yang tersimpan dalam bentuk diferensial Glass (`src/lib/aadi/analysis-view.ts`, `src/components/analysis-document.tsx`): Pembahasan kasus, Kemungkinan utama, Alternatif, Jangan terlewat, Langkah diagnostik berikutnya, Rencana tata laksana (lewat gerbang bukti; dosis yang tidak terverifikasi diberi tanda "Cek dosis obat"), Edukasi dan tindak lanjut, Kutipan pedoman (kartu bernomor, tautan `[n]`). Kartu berpikir hanya melaporkan yang terjadi (permintaan diterima, detik menunggu); jejak pipeline disimpan bersama jawaban. Komposer memakai satu baris chip (8 mode) dan `/` sebagai pemilih penuh. Pengaturan Agent menjadi halaman `/agent` dengan tab Preferensi, Mode dan templat, Pengetahuan; `settings.environment` tampil sebagai pil beranda, `settings.modeInstructions` hanya dipakai draf lokal. Token radius: `--radius-control` 8 px, `--radius-structure` 12 px. Bukti: `docs/verification/glass-redesign-2026-11-04/` (1440, 1024, 375 px; axe 0 pelanggaran).
Menggantikan Clinical Cockpit, rail "Alur kasus", jawaban diketik, dan dialog Pengaturan Agent di atas. Sidebar mengikuti urutan Glass; kanvas terbagi antara chat dan panel dokumen di atas 1200 px (sheet "Dokumen encounter" di bawahnya). Chat berisi prosa, ringkasan dokter, dan kartu dokumen; panel berisi tab Ringkasan encounter dan satu tab per dokumen. Analisis AADI dirender dari hasil mesin yang tersimpan dalam bentuk diferensial Glass (`src/lib/aadi/analysis-view.ts`, `src/components/analysis-document.tsx`): Pembahasan kasus, Kemungkinan utama, Alternatif, Jangan terlewat, Langkah diagnostik berikutnya, Rencana tata laksana (lewat gerbang bukti; dosis yang tidak terverifikasi diberi tanda "Cek dosis obat"), Edukasi dan tindak lanjut, Kutipan pedoman (kartu bernomor, tautan `[n]`). Kartu berpikir hanya melaporkan yang terjadi (permintaan diterima, tahap gateway yang benar-benar dilaporkan sejak 2026-11-26, detik menunggu); jejak pipeline disimpan bersama jawaban. Komposer memakai satu baris chip (8 mode) dan `/` sebagai pemilih penuh. Pengaturan Agent menjadi halaman `/agent` dengan tab Preferensi, Mode dan templat, Pengetahuan; `settings.environment` tampil sebagai pil beranda, `settings.modeInstructions` hanya dipakai draf lokal. Token radius: `--radius-control` 8 px, `--radius-structure` 12 px. Bukti: `docs/verification/glass-redesign-2026-11-04/` (1440, 1024, 375 px; axe 0 pelanggaran).

## Alur kasus yang lebih aman (2026-11-26)

Expand Down
6 changes: 5 additions & 1 deletion src/app/api/aadi/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { syncPrincipal } from "../../../lib/sync/principal";
import { analysisLimits, analysisQueue } from "../../../lib/aadi/server-guards";
import { parseDailyQuota } from "../../../lib/aadi/limits";
import { loadCatalogue } from "../../../lib/theoracle-catalogue";
import { stageStreamType, streamAnalysis } from "../../../lib/aadi/stage-stream";

export const runtime = "nodejs";
export const dynamic = "force-dynamic";
Expand Down Expand Up @@ -43,5 +44,8 @@ export async function POST(request: Request) {
// The evidence gate reads the catalogue index; loading it here keeps a broken data folder from failing silently later.
loadCatalogue();
// The verified session is the principal the line, the daily quota and the budget count against.
return gateway.step(request, syncPrincipal(access.userId) ?? undefined);
const principal = syncPrincipal(access.userId) ?? undefined;
// A workspace that asks for progress gets each stage as it happens, then the same reply as its last line.
if (request.headers.get("accept")?.includes(stageStreamType)) return streamAnalysis(onStage => gateway.step(request, principal, onStage));
return gateway.step(request, principal);
}
41 changes: 30 additions & 11 deletions src/app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -299,15 +299,11 @@ label.button:has(input:focus-visible) { outline: 2px solid var(--workspace-focus
.guideline-citation-tag { font-size: var(--text-xs); font-weight: var(--weight-medium); color: var(--workspace-accent-ink); }
.guideline-citation-text { margin: 0; font-size: var(--text-base); line-height: 1.54; color: var(--color-text-secondary); }
.cite-link { color: var(--workspace-accent-ink); text-decoration: none; }
/* A new section unfolds like a submenu (the branch line draws down), then types. */
/* A new section's branch line, beside the section body. */
.diagnosis-section-body { position: relative; padding-left: 16px; }
.diagnosis-section-body::before { content: ""; position: absolute; left: 3px; top: 2px; bottom: 2px; border-left: 1px solid var(--color-border-subtle); transform-origin: top; transition: border-color 320ms ease-out; }
/* A typing answer streams in word by word like a chat reply (Gaffer, 2026-10-20: "seperti claude.ai"): no fade or
rise on its lines, which arrived every few tens of milliseconds and read as a jitter. */
@keyframes text-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes section-heading-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }
@keyframes section-unfold { to { grid-template-rows: 1fr; } }
@keyframes typing-caret { 50% { opacity: 0; } }
/* While the analysis runs, its steps fold in one after another. */
.thinking-steps { list-style: none; margin: 0 0 10px; padding: 0 0 0 14px; position: relative; }
.thinking-steps li { position: relative; display: flex; align-items: center; gap: 8px; height: 28px; font-size: var(--text-base); color: var(--color-text-secondary); animation: section-heading-in 280ms cubic-bezier(.23, 1, .32, 1); }
Expand All @@ -316,16 +312,18 @@ label.button:has(input:focus-visible) { outline: 2px solid var(--workspace-focus
.thinking-steps li[data-done="true"] { color: var(--color-text-muted); }
.thinking-steps li[data-done="true"] svg { color: var(--workspace-accent-ink); }
.thinking-steps li[data-done="false"] > span:last-child { font-weight: var(--weight-semibold); background: linear-gradient(90deg, var(--color-text-secondary) 0%, var(--color-text-primary) 45%, var(--color-text-secondary) 90%) 0 0 / 200% 100%; -webkit-background-clip: text; background-clip: text; color: transparent; animation: thinking-shimmer 1.6s linear infinite; }
.thinking-skip { width: 12px; text-align: center; color: var(--color-text-muted); }
.thinking-dot { width: 12px; height: 12px; display: inline-flex; align-items: center; justify-content: center; }
.thinking-dot::after { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--color-action-primary); animation: typing-caret 900ms steps(1) infinite; }
.thinking-dot::after { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--color-action-primary); animation: thinking-pulse 1.2s ease-in-out infinite; }
@keyframes thinking-pulse { 50% { opacity: .35; transform: scale(.7); } }
@keyframes thinking-shimmer { to { background-position: -200% 0; } }
@media (max-width: 900px) {
.header-left .workspace-greeting, .header-left .workspace-greeting + .header-divider { display: none; }
.encounter-title { max-width: none; }
}
@media (prefers-reduced-motion: reduce) {
.diagnosis-section-heading h3::after { transition: none; }
.diagnosis-section-body::before, .thinking-steps li, .thinking-steps li > span:last-child { animation: none; }
.diagnosis-section-body::before, .thinking-steps li, .thinking-steps li > span:last-child, .thinking-dot::after { animation: none; }
}
.draft-task { display: flex; gap: 7px; align-items: flex-start; margin: 7px 0; }
.draft-task input { accent-color: var(--workspace-accent-ink); margin-top: 4px; }
Expand Down Expand Up @@ -709,14 +707,35 @@ label.button:has(input:focus-visible) { outline: 2px solid var(--workspace-focus
.chip-row, .dialog[open], .dialog[open]::backdrop, .toast, .home-content, .home-bottom, .conversation, .chat-composer, .user-message, .assistant-message, .header-left > :not(.expand-sidebar), .export-encounter, .panel-scroll, .document-studio > *, .draft-editor, .dialog-inner > :not(.dialog-header), .theoracle-detail, .template-preview, .workflow-form, .form-warning, .studio-columns, .aadi-result, .queue-card, .composer-analysis, .slash-picker, .context-status > span, .storage-warning { animation: fade-in 160ms ease-out; }
@starting-style { .submenu-section[data-open="true"] .submenu-item { opacity: 0; } }
/* Every fresh answer arrives the same way (Gaffer, 2026-10-17: smooth and simple): the card rises softly into focus,
then a still document's blocks follow one by one. An analysis keeps its own typing reveal; a reopened answer appears at once. */
then the document's blocks follow one by one: a template's lines, an AADI analysis's sections. The whole answer is
in the page from the first frame (reading aids, copy and print see all of it); only its opacity and offset ease in,
60 ms apart and capped at the eighth block, so the last block settles within 0.9 s. A reopened answer appears at once. */
.assistant-message[data-reveal] { animation: answer-in 520ms cubic-bezier(.16, 1, .3, 1) both; }
.document-studio[data-reveal] :where(.document-studio > .draft-content > *) { animation: text-in 480ms cubic-bezier(.16, 1, .3, 1) 160ms both; }
@supports (animation-delay: calc(sibling-index() * 1ms)) { .document-studio[data-reveal] :where(.document-studio > .draft-content > *) { animation-delay: calc(100ms + min(sibling-index(), 12) * 60ms); } }
.document-studio[data-reveal] :where(.draft-content, .analysis-document) > * { animation: text-in 480ms cubic-bezier(.16, 1, .3, 1) 100ms both; }
.document-studio[data-reveal] :where(.draft-content, .analysis-document) > :nth-child(2) { animation-delay: 160ms; }
.document-studio[data-reveal] :where(.draft-content, .analysis-document) > :nth-child(3) { animation-delay: 220ms; }
.document-studio[data-reveal] :where(.draft-content, .analysis-document) > :nth-child(4) { animation-delay: 280ms; }
.document-studio[data-reveal] :where(.draft-content, .analysis-document) > :nth-child(5) { animation-delay: 340ms; }
.document-studio[data-reveal] :where(.draft-content, .analysis-document) > :nth-child(6) { animation-delay: 400ms; }
.document-studio[data-reveal] :where(.draft-content, .analysis-document) > :nth-child(7) { animation-delay: 460ms; }
.document-studio[data-reveal] :where(.draft-content, .analysis-document) > :nth-child(n + 8) { animation-delay: 520ms; }
@keyframes answer-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .assistant-message[data-reveal], .document-studio[data-reveal] :where(.document-studio > .draft-content > *) { animation: none; } }
@media (prefers-reduced-motion: reduce) { .assistant-message[data-reveal], .document-studio[data-reveal] :where(.draft-content, .analysis-document) > * { animation: none; } }
::view-transition { pointer-events: none; }
::view-transition-group(root), ::view-transition-old(root), ::view-transition-new(root) { animation-duration: 160ms; animation-timing-function: ease-out; }
/* An answer arriving (wait card out, answer and document pane in): the chat column, its composer and the header tools
glide to their new width and place instead of cross-fading as one picture, which showed both layouts at once. Each
picture keeps its size, pinned top left, so text is never stretched; the pane fades in beside them. */
:root[data-transition="arrive"] .conversation { view-transition-name: arrive-conversation; }
:root[data-transition="arrive"] .chat-composer { view-transition-name: arrive-composer; }
:root[data-transition="arrive"] .header-right { view-transition-name: arrive-tools; }
:root[data-transition="arrive"] .document-pane { view-transition-name: arrive-pane; }
:root[data-transition="arrive"]::view-transition-group(*) { animation-duration: 280ms; animation-timing-function: cubic-bezier(.23, 1, .32, 1); }
:root[data-transition="arrive"]::view-transition-old(*), :root[data-transition="arrive"]::view-transition-new(*) { animation-duration: 200ms; }
:root[data-transition="arrive"]::view-transition-old(arrive-conversation), :root[data-transition="arrive"]::view-transition-new(arrive-conversation),
:root[data-transition="arrive"]::view-transition-old(arrive-composer), :root[data-transition="arrive"]::view-transition-new(arrive-composer),
:root[data-transition="arrive"]::view-transition-old(arrive-tools), :root[data-transition="arrive"]::view-transition-new(arrive-tools) { height: 100%; width: auto; object-fit: none; object-position: left top; overflow: clip; }
:root[data-transition="arrive"]::view-transition-new(arrive-tools), :root[data-transition="arrive"]::view-transition-old(arrive-tools) { object-position: right top; }

/* Design audit fixes (Gaffer, 2026-10-11). */
/* D-04: the Encounter title is the page heading in chat view, in the header's own type. */
Expand Down
8 changes: 6 additions & 2 deletions src/components/smooth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import { flushSync } from "react-dom";

// A short cross-fade for changes that remove or reflow content (dialogs closing, sidebar, panels),
// which CSS alone cannot fade out. Opacity only; reduced motion and older browsers apply the change at once.
export function smooth(update: () => void) {
// kind names a transition with its own timing in globals.css (:root[data-transition]); it is cleared when the fade ends.
export function smooth(update: () => void, kind?: "arrive") {
if (typeof document.startViewTransition !== "function" || window.matchMedia("(prefers-reduced-motion: reduce)").matches) { update(); return; }
document.startViewTransition(() => flushSync(update));
const root = document.documentElement;
if (kind && root) root.dataset.transition = kind;
const transition = document.startViewTransition(() => flushSync(update));
if (kind && root) void transition?.finished?.finally(() => { if (root.dataset.transition === kind) delete root.dataset.transition; });
}
32 changes: 28 additions & 4 deletions src/components/thinking-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,45 @@

import { Check } from "lucide-react";
import { useEffect, useState } from "react";
import type { AnalysisStage, StageEvent } from "../lib/aadi/stage-stream";

/** The answer's place while the analysis runs. It reports only what has happened: the request went out, and
* how long the workspace has been waiting. The gateway's stages arrive with the answer (Jejak analisis). */
export function ThinkingCard({ onCancel, startedAt }: { onCancel: () => void; startedAt?: number }) {
// What each gateway stage is doing, in the doctor's words. Only stages the gateway reports are shown.
export const stageLabels: Record<AnalysisStage, string> = {
retrieve_dx: "Mencari referensi Oracle",
aadi_dx: "Menyusun diagnosis banding",
retrieve_tx: "Mencari referensi terapi",
aadi_tx: "Menyusun usulan terapi",
gate: "Memeriksa dosis terhadap referensi",
};

/** The latest state of each reported stage, in the order the stages first appeared. */
export function stageProgress(events: readonly StageEvent[]): StageEvent[] {
const latest = new Map<AnalysisStage, StageEvent>();
for (const event of events) latest.set(event.stage, event);
return [...latest.values()];
}

/** The answer's place while the analysis runs. It reports only what has happened: the request went out, each stage the
* gateway has reported (when it streams them), and how long the workspace has been waiting. Nothing is predicted. */
export function ThinkingCard({ onCancel, startedAt, stages = [] }: { onCancel: () => void; startedAt?: number; stages?: readonly StageEvent[] }) {
// The card mounts when the request goes out, so its mount is the start unless the caller knows better.
const [started] = useState(() => startedAt ?? performance.now());
const [seconds, setSeconds] = useState(() => elapsed(started));
useEffect(() => {
const timer = setInterval(() => setSeconds(elapsed(started)), 1000);
return () => clearInterval(timer);
}, [started]);
const progress = stageProgress(stages);
const running = progress.some((step) => step.state === "running");
return <article className="assistant-message thinking-card" aria-busy="true">
<div role="status" aria-live="polite"><ol className="thinking-steps">
<li data-done="true"><Check size={12} aria-hidden="true"/><span>Permintaan diterima</span></li>
<li data-done="false"><span className="thinking-dot" aria-hidden="true"/><span>Menunggu jawaban AADI · {seconds} dtk</span></li>
{progress.map((step) => step.state === "running"
? <li key={step.stage} data-done="false"><span className="thinking-dot" aria-hidden="true"/><span>{stageLabels[step.stage]} · {seconds} dtk</span></li>
: <li key={step.stage} data-done="true">{step.state === "done" ? <Check size={12} aria-hidden="true"/> : <span className="thinking-skip" aria-hidden="true">–</span>}<span>{stageLabels[step.stage]}{step.state === "failed" ? " · tidak berhasil" : ""}</span></li>)}
{/* Before the first stage (or from a gateway that sends none) the wait itself is the step; after the last one the
gateway is assembling the reply. */}
{!running && <li data-done="false"><span className="thinking-dot" aria-hidden="true"/><span>{progress.length ? "Menyelesaikan jawaban" : "Menunggu jawaban AADI"} · {seconds} dtk</span></li>}
</ol></div>
<button type="button" className="text-button" onClick={onCancel}>Batalkan analisis</button>
</article>;
Expand Down
Loading
Loading