From 8bb0fccd02cb91560003588f7aa9b5a1b2a40d27 Mon Sep 17 00:00:00 2001 From: "penify-dev[bot]" <146478655+penify-dev[bot]@users.noreply.github.com> Date: Wed, 17 Sep 2025 15:22:32 +0000 Subject: [PATCH 1/5] [Penify]: Documentation for commit - fdcc926 --- next-app/app/api/chat/stream/route.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/next-app/app/api/chat/stream/route.ts b/next-app/app/api/chat/stream/route.ts index 1e7bf8b..e0b32b7 100644 --- a/next-app/app/api/chat/stream/route.ts +++ b/next-app/app/api/chat/stream/route.ts @@ -10,6 +10,16 @@ function* fakeStream(text: string) { import { preFilter, steerPrompt, postModerate } from '@/lib/safety/pipeline'; +/** + * Streams a message as a server-sent event. + * + * This function creates a ReadableStream that processes a given message through several stages: + * it applies pre-filtering, steering, and post-moderation to generate a reply. The stream emits + * metadata and each chunk of the reply as events, handling errors by sending an error event if + * any exceptions occur during processing. + * + * @param message - The input message to be processed and streamed. + */ function streamForMessage(message: string) { const ctrl = new AbortController(); const stream = new ReadableStream({ From 531e5ee6b8ec1c54ff4ce2d31a0455068b625806 Mon Sep 17 00:00:00 2001 From: "penify-dev[bot]" <146478655+penify-dev[bot]@users.noreply.github.com> Date: Wed, 17 Sep 2025 15:22:33 +0000 Subject: [PATCH 2/5] [Penify]: Documentation for commit - fdcc926 --- next-app/app/api/consent/route.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/next-app/app/api/consent/route.ts b/next-app/app/api/consent/route.ts index 704ba53..8ed6529 100644 --- a/next-app/app/api/consent/route.ts +++ b/next-app/app/api/consent/route.ts @@ -3,6 +3,15 @@ import { appendConsentEvent, exportConsent } from '@/lib/privacy/consentLedger'; export const runtime = 'nodejs'; +/** + * Handles POST requests to process user consent actions. + * + * This function extracts the userId, sessionId, and action from the request body. + * It validates the action against a predefined list and returns a 400 response for invalid actions. + * If the action is valid, it appends a consent event using the appendConsentEvent function and returns the result as a JSON response. + * + * @param req - The NextRequest object containing the request data. + */ export async function POST(req: NextRequest) { const { userId = 'demo', sessionId, action } = await req.json(); if (!['persist_on','persist_off','export'].includes(action)) return new Response('bad action', { status: 400 }); @@ -10,6 +19,9 @@ export async function POST(req: NextRequest) { return Response.json(ev); } +/** + * Handles GET requests and returns consent data for a user. + */ export async function GET(req: NextRequest) { const { searchParams } = new URL(req.url); const userId = searchParams.get('userId') ?? 'demo'; From 2fad89ac2ffa7a92d751cd6238b9dc8587be7a57 Mon Sep 17 00:00:00 2001 From: "penify-dev[bot]" <146478655+penify-dev[bot]@users.noreply.github.com> Date: Wed, 17 Sep 2025 15:22:34 +0000 Subject: [PATCH 3/5] [Penify]: Documentation for commit - fdcc926 --- next-app/app/api/risk/scores/route.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/next-app/app/api/risk/scores/route.ts b/next-app/app/api/risk/scores/route.ts index e160a18..4f95578 100644 --- a/next-app/app/api/risk/scores/route.ts +++ b/next-app/app/api/risk/scores/route.ts @@ -1,4 +1,7 @@ export const runtime = 'nodejs'; +/** + * Handles the GET request and returns a mock time-series risk per layer. + */ export async function GET() { // Mock time-series risk per layer: core/operational/context const now = Date.now(); @@ -8,4 +11,7 @@ export async function GET() { })); return Response.json({ series }); } +/** + * Clamps a value between a minimum and maximum range. + */ function clamp(min:number,max:number,v:number){return Math.max(min,Math.min(max,v));} From 363d1800e6690e8b304e86bd156e267bef7152c4 Mon Sep 17 00:00:00 2001 From: "penify-dev[bot]" <146478655+penify-dev[bot]@users.noreply.github.com> Date: Wed, 17 Sep 2025 15:22:36 +0000 Subject: [PATCH 4/5] [Penify]: Documentation for commit - fdcc926 --- next-app/app/chat/page.tsx | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/next-app/app/chat/page.tsx b/next-app/app/chat/page.tsx index 9427427..c75b9c9 100644 --- a/next-app/app/chat/page.tsx +++ b/next-app/app/chat/page.tsx @@ -2,6 +2,13 @@ import { useEffect, useRef, useState } from 'react'; import { ProvenanceBadge } from '@/components/ProvenanceBadge'; +/** + * Renders the chat page interface and handles message sending and streaming. + * + * 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. + * + * @returns {JSX.Element} The rendered chat page component. + */ export default function ChatPage() { const [input, setInput] = useState(""); const [messages, setMessages] = useState<{ role: 'user'|'assistant'; content: string; meta?: any }[]>([]); From 25db400676b09fbe50f6c49067d2c38dd31beeb3 Mon Sep 17 00:00:00 2001 From: "penify-dev[bot]" <146478655+penify-dev[bot]@users.noreply.github.com> Date: Wed, 17 Sep 2025 15:22:37 +0000 Subject: [PATCH 5/5] [Penify]: Documentation for commit - fdcc926 --- next-app/app/docs/governance-terms-mapping/page.tsx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/next-app/app/docs/governance-terms-mapping/page.tsx b/next-app/app/docs/governance-terms-mapping/page.tsx index 979cdbb..3c77d3f 100644 --- a/next-app/app/docs/governance-terms-mapping/page.tsx +++ b/next-app/app/docs/governance-terms-mapping/page.tsx @@ -1,6 +1,9 @@ import { readFileSync } from 'fs'; import path from 'path'; export const dynamic = 'force-static'; +/** + * Renders the content of a markdown file as preformatted text. + */ export default function Page() { const md = readFileSync(path.join(process.cwd(), 'next-app', 'docs', 'governance-terms-mapping.md'), 'utf8'); return
{md}
;