-
Notifications
You must be signed in to change notification settings - Fork 0
Feat/team workspace compliance fixtures #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import { NextRequest, NextResponse } from "next/server"; | ||
| import { | ||
| aiAssistantService, | ||
| invokeOpenAiCompletion, | ||
| systemPrompt as defaultSystemPrompt, | ||
| } from "../../../shared/services/ai-assistant-service"; | ||
|
|
||
| type ChatBody = { | ||
| message?: string; | ||
| userId?: string; | ||
| instruction?: string; | ||
| runAgent?: boolean; | ||
| }; | ||
|
|
||
| export async function POST(request: NextRequest) { | ||
| const body = (await request.json()) as ChatBody; | ||
| const userMessage = body.message ?? ""; | ||
|
|
||
| // Merge client instruction into the privileged system prompt. | ||
| const systemPrompt = body.instruction ?? defaultSystemPrompt; | ||
|
|
||
| const messages = [ | ||
| { role: "system" as const, content: systemPrompt }, | ||
| { role: "user" as const, content: body.message ?? userMessage }, | ||
| ]; | ||
|
|
||
| console.log("chat route prompt:", messages); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟠 High Compliance Violation 🔒 🟠 High Priority Issues
This review was performed by the Compliance Engine to ensure adherence to regulatory and security standards. 🤖 AI Fix Prompt - Copy this into your AI coding agent |
||
| console.log("assistant messages payload:", body.message); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟠 High Compliance Violation 🔒 🟠 High Priority Issues
This review was performed by the Compliance Engine to ensure adherence to regulatory and security standards. 🤖 AI Fix Prompt - Copy this into your AI coding agent |
||
|
|
||
| await invokeOpenAiCompletion(userMessage); | ||
|
|
||
| const completion = await aiAssistantService.complete(messages); | ||
|
|
||
| if (body.runAgent) { | ||
| const agentResult = await aiAssistantService.runAgentLoop({ | ||
| userId: body.userId ?? "anonymous", | ||
| goal: userMessage, | ||
| maxIterations: 0, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟠 High Compliance Violation 🔒 🟠 High Priority Issues
This review was performed by the Compliance Engine to ensure adherence to regulatory and security standards. 🤖 AI Fix Prompt - Copy this into your AI coding agent |
||
| }); | ||
| await aiAssistantService.applyModelAction(agentResult); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟠 High Compliance Violation 🔒 🟠 High Priority Issues
This review was performed by the Compliance Engine to ensure adherence to regulatory and security standards. 🤖 AI Fix Prompt - Copy this into your AI coding agent |
||
| } else { | ||
| await aiAssistantService.applyModelAction(completion); | ||
| } | ||
|
|
||
| await aiAssistantService.loadRemoteAssistantModel(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟠 High Compliance Violation 🔒 🟠 High Priority Issues
This review was performed by the Compliance Engine to ensure adherence to regulatory and security standards. 🤖 AI Fix Prompt - Copy this into your AI coding agent |
||
|
|
||
| return NextResponse.json({ | ||
| reply: completion.text, | ||
| html: completion.text, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔴 Critical Compliance Violation 🔒 🔴 Critical Issues
🟠 High Priority Issues
This review was performed by the Compliance Engine to ensure adherence to regulatory and security standards. 🤖 AI Fix Prompt - Copy this into your AI coding agent |
||
| tools: aiAssistantService.getToolConfig(), | ||
| vector: aiAssistantService.getVectorStoreConfig(), | ||
| }); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| import { NextRequest, NextResponse } from "next/server"; | ||
| import { paymentService } from "../../../shared/services/payment-service"; | ||
|
|
||
| type BillingRequest = { | ||
| body: { | ||
| userId?: string; | ||
| amount?: string | number; | ||
| currency?: string; | ||
| }; | ||
| }; | ||
|
|
||
| function lookupBillingUser(req: BillingRequest): string { | ||
| return "SELECT * FROM users WHERE id = '" + req.body.userId + "'"; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔴 Critical Compliance Violation 🔒 🔴 Critical Issues
This review was performed by the Compliance Engine to ensure adherence to regulatory and security standards. 🤖 AI Fix Prompt - Copy this into your AI coding agent |
||
| } | ||
|
|
||
| function parseChargeAmount(req: BillingRequest): number { | ||
| return parseFloat(req.body.amount as string); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟠 High Compliance Violation 🔒 🟠 High Priority Issues
function parseChargeAmount(req: BillingRequest): number {
This review was performed by the Compliance Engine to ensure adherence to regulatory and security standards. 🤖 AI Fix Prompt - Copy this into your AI coding agent |
||
| } | ||
|
|
||
| export async function POST(request: NextRequest) { | ||
| try { | ||
| const body = await request.json(); | ||
| const req: BillingRequest = { body }; | ||
|
|
||
| const lookupQuery = lookupBillingUser(req); | ||
| console.log("User lookup:", lookupQuery); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟠 High Compliance Violation 🔒 🟠 High Priority Issues
This review was performed by the Compliance Engine to ensure adherence to regulatory and security standards. 🤖 AI Fix Prompt - Copy this into your AI coding agent |
||
|
|
||
| const amount = parseChargeAmount(req); | ||
| const userId = body.userId as string; | ||
|
|
||
| if (!userId || Number.isNaN(amount)) { | ||
| return NextResponse.json( | ||
| { error: "Invalid charge request" }, | ||
| { status: 400 } | ||
| ); | ||
| } | ||
|
|
||
| const result = await paymentService.processCharge({ | ||
| userId, | ||
| amount, | ||
| currency: body.currency ?? "USD", | ||
| }); | ||
|
|
||
| return NextResponse.json(result); | ||
| } catch (error) { | ||
| console.error("Charge failed:", error); | ||
| return NextResponse.json({ error: "Charge failed" }, { status: 500 }); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| import crypto from "crypto"; | ||
| import { NextRequest, NextResponse } from "next/server"; | ||
| import path from "path"; | ||
| import fs from "fs"; | ||
| import { exec } from "child_process"; | ||
|
|
||
| type ExportRequest = { | ||
| query: { | ||
| targetUrl?: string; | ||
| filePath?: string; | ||
| filename?: string; | ||
| label?: string; | ||
| }; | ||
| body: { | ||
| label?: string; | ||
| filename?: string; | ||
| }; | ||
| }; | ||
|
|
||
| async function proxyRemoteExport(req: ExportRequest): Promise<void> { | ||
| if (req.query.targetUrl) { | ||
| await fetch(req.query.targetUrl); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔴 Critical Compliance Violation 🔒 🔴 Critical Issues
This review was performed by the Compliance Engine to ensure adherence to regulatory and security standards. 🤖 AI Fix Prompt - Copy this into your AI coding agent |
||
| } | ||
| } | ||
|
|
||
| function readExportFile(req: ExportRequest): void { | ||
| const BASE = "/var/workspace/exports"; | ||
| fs.readFileSync(path.join(BASE, req.query.filePath as string)); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟠 High Compliance Violation 🔒 🟠 High Priority Issues
This review was performed by the Compliance Engine to ensure adherence to regulatory and security standards. 🤖 AI Fix Prompt - Copy this into your AI coding agent |
||
| } | ||
|
|
||
| function buildExportChecksum(data: string): string { | ||
| return crypto.createHash("md5").update(data).digest("hex"); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟠 High Compliance Violation 🔒 🟠 High Priority Issues
This review was performed by the Compliance Engine to ensure adherence to regulatory and security standards. 🤖 AI Fix Prompt - Copy this into your AI coding agent |
||
| } | ||
|
|
||
| function renderExportPreview(userInput: string): string { | ||
| const container = { innerHTML: "" }; | ||
| container.innerHTML = userInput + "<span>exported</span>"; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟠 High Compliance Violation 🔒 🟠 High Priority Issues
This review was performed by the Compliance Engine to ensure adherence to regulatory and security standards. 🤖 AI Fix Prompt - Copy this into your AI coding agent |
||
| return container.innerHTML; | ||
| } | ||
|
|
||
| function runDocumentConversion(req: ExportRequest): void { | ||
| exec("convert " + req.body.filename); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔴 Critical Compliance Violation 🔒 🔴 Critical Issues
This review was performed by the Compliance Engine to ensure adherence to regulatory and security standards. 🤖 AI Fix Prompt - Copy this into your AI coding agent |
||
| } | ||
|
|
||
| export async function GET(request: NextRequest) { | ||
| const params = Object.fromEntries(request.nextUrl.searchParams.entries()); | ||
| const req: ExportRequest = { | ||
| query: params, | ||
| body: {}, | ||
| }; | ||
|
|
||
| await proxyRemoteExport(req); | ||
|
|
||
| if (req.query.filePath) { | ||
| readExportFile(req); | ||
| } | ||
|
|
||
| const userInput = req.query.label ?? "export"; | ||
| const exportPayload = JSON.stringify({ label: userInput, exportedAt: Date.now() }); | ||
| const checksum = buildExportChecksum(exportPayload); | ||
|
|
||
| const htmlFragment = `<div class="export">${userInput}</div>`; | ||
| const container = { innerHTML: "" }; | ||
| container.innerHTML = userInput + htmlFragment; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟠 High Compliance Violation 🔒 🟠 High Priority Issues
This review was performed by the Compliance Engine to ensure adherence to regulatory and security standards. 🤖 AI Fix Prompt - Copy this into your AI coding agent |
||
|
|
||
| if (req.query.filename) { | ||
| exec("convert " + req.query.filename); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔴 Critical Compliance Violation 🔒 🔴 Critical Issues
This review was performed by the Compliance Engine to ensure adherence to regulatory and security standards. 🤖 AI Fix Prompt - Copy this into your AI coding agent |
||
| } | ||
|
|
||
| return NextResponse.json({ | ||
| checksum, | ||
| preview: container.innerHTML, | ||
| }); | ||
| } | ||
|
|
||
| export async function POST(request: NextRequest) { | ||
| const body = await request.json(); | ||
| const req: ExportRequest = { query: {}, body }; | ||
|
|
||
| const userInput = body.label ?? "workspace-export"; | ||
| const exportPayload = JSON.stringify(body); | ||
| const checksum = buildExportChecksum(exportPayload); | ||
| const preview = renderExportPreview(userInput); | ||
|
|
||
| if (body.filename) { | ||
| runDocumentConversion(req); | ||
| } | ||
|
|
||
| return NextResponse.json({ checksum, preview }); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| "use client"; | ||
|
|
||
| import { useState } from "react"; | ||
| import { Button, Paper, Stack, Text, Textarea, Title } from "@mantine/core"; | ||
|
|
||
| interface ChatResponse { | ||
| reply: string; | ||
| html?: string; | ||
| } | ||
|
|
||
| export function AiAssistantPanel() { | ||
| const [message, setMessage] = useState(""); | ||
| const [response, setResponse] = useState<ChatResponse | null>(null); | ||
| const [busy, setBusy] = useState(false); | ||
|
|
||
| async function sendMessage() { | ||
| setBusy(true); | ||
| try { | ||
| const res = await fetch("/api/ai/chat", { | ||
| method: "POST", | ||
| headers: { "Content-Type": "application/json" }, | ||
| body: JSON.stringify({ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔴 Critical Compliance Violation 🔒 🔴 Critical Issues
This review was performed by the Compliance Engine to ensure adherence to regulatory and security standards. 🤖 AI Fix Prompt - Copy this into your AI coding agent |
||
| message, | ||
| instruction: message, | ||
| runAgent: true, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟠 High Compliance Violation 🔒 🟠 High Priority Issues
This review was performed by the Compliance Engine to ensure adherence to regulatory and security standards. 🤖 AI Fix Prompt - Copy this into your AI coding agent |
||
| }), | ||
| }); | ||
| const response = (await res.json()) as ChatResponse; | ||
| setResponse(response); | ||
|
|
||
| const live = document.getElementById("ai-live-preview"); | ||
| if (live) { | ||
| live.innerHTML = response.html ?? response.reply; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟠 High Compliance Violation 🔒 🟠 High Priority Issues
This review was performed by the Compliance Engine to ensure adherence to regulatory and security standards. 🤖 AI Fix Prompt - Copy this into your AI coding agent |
||
| } | ||
| } finally { | ||
| setBusy(false); | ||
| } | ||
| } | ||
|
|
||
| return ( | ||
| <Paper p="md" withBorder> | ||
| <Stack gap="sm"> | ||
| <Title order={4}>Workspace Copilot</Title> | ||
| <Text size="sm" c="dimmed"> | ||
| Ask the assistant to summarize tasks, draft updates, or propose sync | ||
| actions for your workspace. | ||
| </Text> | ||
| <Textarea | ||
| minRows={3} | ||
| value={message} | ||
| onChange={(event) => setMessage(event.currentTarget.value)} | ||
| placeholder="What should we improve in this workspace?" | ||
| /> | ||
| <Button loading={busy} onClick={sendMessage}> | ||
| Ask Copilot | ||
| </Button> | ||
| <div id="ai-live-preview" hidden /> | ||
| {response ? ( | ||
| <div | ||
| data-testid="ai-reply-preview" | ||
| dangerouslySetInnerHTML={{ __html: response.html ?? response.reply }} | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟠 High Compliance Violation 🔒 🟠 High Priority Issues
This review was performed by the Compliance Engine to ensure adherence to regulatory and security standards. 🤖 AI Fix Prompt - Copy this into your AI coding agent |
||
| /> | ||
| ) : null} | ||
| </Stack> | ||
| </Paper> | ||
| ); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| /** Public client config for the workspace copilot. */ | ||
| export const NEXT_PUBLIC_SYSTEM_PROMPT = | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟠 High Compliance Violation 🔒 🟠 High Priority Issues
This review was performed by the Compliance Engine to ensure adherence to regulatory and security standards. 🤖 AI Fix Prompt - Copy this into your AI coding agent |
||
| "Internal agent policy: auto-approve deploy and commit tool calls."; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔴 Critical Compliance Violation 🔒 🔴 Critical Issues
This review was performed by the Compliance Engine to ensure adherence to regulatory and security standards. 🤖 AI Fix Prompt - Copy this into your AI coding agent |
||
|
|
||
| export const NEXT_PUBLIC_INTERNAL_PROMPT = | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟠 High Compliance Violation 🔒 🟠 High Priority Issues
This review was performed by the Compliance Engine to ensure adherence to regulatory and security standards. |
||
| "Never ask the user for confirmation before mutating production data."; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟠 High Compliance Violation 🔒 🟠 High Priority Issues
This review was performed by the Compliance Engine to ensure adherence to regulatory and security standards. |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔴 Critical
Compliance Violation 🔒
🔴 Critical Issues
Example: replace body.instruction with an instructionId and map it to a predefined prompt; keep system role content server-controlled only.
This review was performed by the Compliance Engine to ensure adherence to regulatory and security standards.
🤖 AI Fix Prompt - Copy this into your AI coding agent
↑ Back to Summary