Skip to content

Commit 46420d2

Browse files
Merge pull request #14 from OneFineStarstuff/penify/auto_doc_fdcc926_f30af
[Penify]: Documentation for commit - fdcc926
2 parents fdcc926 + 25db400 commit 46420d2

5 files changed

Lines changed: 38 additions & 0 deletions

File tree

next-app/app/api/chat/stream/route.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ function* fakeStream(text: string) {
1010

1111
import { preFilter, steerPrompt, postModerate } from '@/lib/safety/pipeline';
1212

13+
/**
14+
* Streams a message as a server-sent event.
15+
*
16+
* This function creates a ReadableStream that processes a given message through several stages:
17+
* it applies pre-filtering, steering, and post-moderation to generate a reply. The stream emits
18+
* metadata and each chunk of the reply as events, handling errors by sending an error event if
19+
* any exceptions occur during processing.
20+
*
21+
* @param message - The input message to be processed and streamed.
22+
*/
1323
function streamForMessage(message: string) {
1424
const ctrl = new AbortController();
1525
const stream = new ReadableStream<Uint8Array>({

next-app/app/api/consent/route.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,25 @@ import { appendConsentEvent, exportConsent } from '@/lib/privacy/consentLedger';
33

44
export const runtime = 'nodejs';
55

6+
/**
7+
* Handles POST requests to process user consent actions.
8+
*
9+
* This function extracts the userId, sessionId, and action from the request body.
10+
* It validates the action against a predefined list and returns a 400 response for invalid actions.
11+
* If the action is valid, it appends a consent event using the appendConsentEvent function and returns the result as a JSON response.
12+
*
13+
* @param req - The NextRequest object containing the request data.
14+
*/
615
export async function POST(req: NextRequest) {
716
const { userId = 'demo', sessionId, action } = await req.json();
817
if (!['persist_on','persist_off','export'].includes(action)) return new Response('bad action', { status: 400 });
918
const ev = await appendConsentEvent({ userId, sessionId, action, ts: new Date().toISOString() as any });
1019
return Response.json(ev);
1120
}
1221

22+
/**
23+
* Handles GET requests and returns consent data for a user.
24+
*/
1325
export async function GET(req: NextRequest) {
1426
const { searchParams } = new URL(req.url);
1527
const userId = searchParams.get('userId') ?? 'demo';

next-app/app/api/risk/scores/route.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
export const runtime = 'nodejs';
2+
/**
3+
* Handles the GET request and returns a mock time-series risk per layer.
4+
*/
25
export async function GET() {
36
// Mock time-series risk per layer: core/operational/context
47
const now = Date.now();
@@ -8,4 +11,7 @@ export async function GET() {
811
}));
912
return Response.json({ series });
1013
}
14+
/**
15+
* Clamps a value between a minimum and maximum range.
16+
*/
1117
function clamp(min:number,max:number,v:number){return Math.max(min,Math.min(max,v));}

next-app/app/chat/page.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22
import { useEffect, useRef, useState } from 'react';
33
import { ProvenanceBadge } from '@/components/ProvenanceBadge';
44

5+
/**
6+
* Renders the chat page interface and handles message sending and streaming.
7+
*
8+
* The function manages the state for user input, messages, and streaming status. It sets up an EventSource to listen for incoming messages and updates the message list accordingly. It also handles fallback scenarios and cleans up the EventSource on component unmount.
9+
*
10+
* @returns {JSX.Element} The rendered chat page component.
11+
*/
512
export default function ChatPage() {
613
const [input, setInput] = useState("");
714
const [messages, setMessages] = useState<{ role: 'user'|'assistant'; content: string; meta?: any }[]>([]);

next-app/app/docs/governance-terms-mapping/page.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { readFileSync } from 'fs';
22
import path from 'path';
33
export const dynamic = 'force-static';
4+
/**
5+
* Renders the content of a markdown file as preformatted text.
6+
*/
47
export default function Page() {
58
const md = readFileSync(path.join(process.cwd(), 'next-app', 'docs', 'governance-terms-mapping.md'), 'utf8');
69
return <pre className="whitespace-pre-wrap text-sm">{md}</pre>;

0 commit comments

Comments
 (0)