Daedalus-Lite's 3-step middleware architecture makes it infinitely extensible. Intercept, enrich, format, and audit AI interactions for any domain.
Prepend portfolio context and automatically enforce regulatory disclaimer injection on output.
import type { Middleware } from './types.js'; export const financialGuardMiddleware: Middleware = async (req, next) => { req.prompt = `You are a financial assistant. Always include disclaimers. Never give specific stock advice. Answer in plain language. User question: ${req.prompt}`; const response = await next(); // Post-process: ensure disclaimer is present const content = response.choices[0].message.content; if (!content.includes('consult a financial advisor')) { response.choices[0].message.content += '\n\n *This is not financial advice. Consult a qualified professional.*'; } return response;
}; Inject system-level code review instructions and enforce structured review checklist output.
import type { Middleware } from './types.js'; export const codeReviewMiddleware: Middleware = async (req, next) => { req.prompt = `You are a senior code reviewer. Review the following code for:
1. Security vulnerabilities
2. Performance issues
3. Code style violations
4. Missing error handling
5. Test coverage gaps Format your response as a checklist with severity levels ( CRITICAL, WARNING, INFO). Code to review:
${req.prompt}`; return next();
}; Add context-aware legal disclaimers and enforce strict JSON schema output parsing.
import type { Middleware } from './types.js'; export const legalMiddleware: Middleware = async (req, next) => { req.prompt = `You are a legal document analyst. Identify:
- Key clauses and obligations
- Potential risks
- Missing standard provisions Document: ${req.prompt} Output as a structured JSON object with sections: summary, risks, recommendations.`; return next();
}; Add privacy guardrails and categorize symptom urgency without prescribing or diagnosing.
import type { Middleware } from './types.js'; export const medicalTriageMiddleware: Middleware = async (req, next) => { req.prompt = `You are a medical triage assistant. You do NOT diagnose or prescribe. Help users understand when to seek care. Symptom description: ${req.prompt} Respond with:
1. Urgency level (EMERGENCY / URGENT / ROUTINE / SELF-CARE)
2. Recommended next steps
3. Questions for their doctor Always include: "This is not medical advice. Consult a healthcare provider."`; return next();
}; Inject company knowledge base context dynamically and automatically escalate frustrated customers.
import type { Middleware } from './types.js'; const knowledgeBase = `Product pricing: $29/mo. Refund policy: 30-day guarantee. Support: 24/7.`; export const supportMiddleware: Middleware = async (req, next) => { req.prompt = `Customer support bot for Acme SaaS. Knowledge Base:\n${knowledgeBase}\nCustomer: ${req.prompt}`; const response = await next(); if (req.prompt.match(/angry|frustrated|refund|cancel/i)) { response.choices[0].message.content += '\n\n Flagged for priority support team follow-up.'; } return response;
}; Multi-language conversational practice with inline translations and grammar corrections.
import type { Middleware } from './types.js'; export const languageTutorMiddleware: Middleware = async (req, next) => { req.prompt = `You are a Spanish language tutor. Respond in Spanish, provide English translations in parentheses for new vocabulary, and correct grammar errors.\nStudent: ${req.prompt}`; return next();
}; Parse unstructured raw text into validated JSON data structures.
import type { Middleware } from './types.js'; export const extractionMiddleware: Middleware = async (req, next) => { req.prompt = `Extract structured data from text. Return ONLY valid JSON with fields: entities, dates, summary.\nText: ${req.prompt}`; return next();
}; Chain multiple middleware functions together for logging, auth, rate limiting, and error handling.
import { InMemoryRouter } from './router.js'; const router = new InMemoryRouter({ defaultModel: 'gpt-4' }); // Chain middleware in execution order
router.use(loggingMiddleware); // 1. Audit log
router.use(authMiddleware); // 2. Validate API key
router.use(rateLimitMiddleware); // 3. Throttle requests
router.use(contextInjector); // 4. Inject prompt context
router.use(responseFormatter); // 5. Format output
router.use(errorHandlerMiddleware); // 6. Global error safety net Daedalus is the ultimate proof of concept of what can be built on top of Daedalus-Lite. It takes this core middleware foundation and extends it into a full-scale AI coding assistant with:
/image commandDaedalus-Lite gives you the foundation. What you build on top is up to you.