14}
15// Simple hook for mobile menu toggle
16function useMobileMenu() {
17const [isOpen, setIsOpen] = useState(false);
18const toggleMenu = () => setIsOpen(!isOpen);
2223// Simple hook for tracking current hash for active nav styling
24function useCurrentHash() {
25const [currentHash, setCurrentHash] = useState(() => window.location.hash.slice(1));
2637}
3839export function App({ initialData }: AppProps) {
40// initialData
41const { demoData, loading, error } = initialData;
GlancerpollEnabledStatus.ts1 match
1export async function pollEnabledStatus() {
2// this shouldn't run forever just b/c someone forgot to close their browser tab with the demo in it
3const interval = 1000; // 10000;
openai_enrichmentindex.ts5 matches
26}
2728export default async function (req: Request): Promise<Response> {
29// Only allow POST requests with form data
30if (req.method !== "POST") {
161}
162163// Helper function to extract sections from the response
164function extractSection(content: string, sectionName: string): string {
165const regex = new RegExp(
166`${sectionName}:?\\s*([\\s\\S]*?)(?=\\n\\d+\\.|\\n[A-Z_]+:|$)`,
171}
172173// Helper function to extract sources
174function extractSources(content: string): string[] {
175const sourcesSection = extractSection(content, "SOURCES");
176if (sourcesSection === "No information found") {
GetDustAgentsmain.tsx1 match
1// File: syncDustAgents.ts
2export default async function syncDustAgents(req: Request): Promise<Response> {
3// Only allow POST
4if (req.method !== "POST") {
untitled-4158main.tsx14 matches
33* Utility to create a standardized ACP object.
34*/
35function createAcp(
36source_step_id: string,
37status: ACPStatus,
56* Simulated Tool: Searches application logs for errors.
57*/
58async function logSearchTool(serviceName: string, timeWindow: string): Promise<any> {
59console.log(`TOOL: Searching logs for service "${serviceName}" in the last ${timeWindow}...`);
60await new Promise(res => setTimeout(res, 250)); // Simulate network delay
72* Simulated Tool: Checks the current status of a system component.
73*/
74async function systemStatusTool(serviceName: string): Promise<any> {
75console.log(`TOOL: Checking current status of "${serviceName}"...`);
76await new Promise(res => setTimeout(res, 250));
87* Agent 1: Parses and normalizes the initial alert.
88*/
89async function triageAgent(inputAcp: ACP): Promise<ACP> {
90console.log("AGENT: Triage Agent running...");
91const alert = inputAcp.payload.content;
102* Agent 2: Gathers additional context using tools.
103*/
104async function dataEnrichmentAgent(inputAcp: ACP): Promise<ACP> {
105console.log("AGENT: Data Enrichment Agent running...");
106const { service_name } = inputAcp.payload.content;
123* Agent 3: Analyzes data and proposes a remediation plan. (REAL OpenAI Call)
124*/
125async function rootCauseAnalysisAgent(
126enrichedData: any,
127safetyFeedback?: string,
174* Agent 4: The Safety Gate. Checks the plan for dangerous operations.
175*/
176async function safetyCheckerAgent(inputAcp: ACP): Promise<ACP> {
177console.log(`AGENT: Safety Checker Agent running...`);
178await new Promise(res => setTimeout(res, 200));
195* Agent 5: Formats the final approved plan into an executable script.
196*/
197async function remediationFormatterAgent(inputAcp: ACP): Promise<ACP> {
198console.log("AGENT: Remediation Formatter Agent running...");
199const { remediation_plan } = inputAcp.payload.content;
214// --- Workflow Orchestrator --- //
215216async function runIncidentResponseWorkflow(
217alertPayload: object,
218safetyFeedback?: string,
257// --- HTML Front-End --- //
258259function generateHtmlShell() {
260return `
261<!DOCTYPE html>
327let originalAlertPayload = '';
328329function logStatus(message, type) {
330statusLogEl.innerHTML += \`<div class="log-entry \${type}">\${message.replace(/</g, "<").replace(/>/g, ">")}</div>\`;
331}
332
333function setLoading(isLoading) {
334startBtn.disabled = isLoading;
335approveBtn.disabled = isLoading;
380approveBtn.addEventListener('click', () => continueWorkflow('approved'));
381382async function continueWorkflow(decision) {
383setLoading(true);
384humanApprovalEl.style.display = 'none';
429// --- Main HTTP Request Handler --- //
430431export default async function(req: Request) {
432const url = new URL(req.url);
433const action = url.searchParams.get("action");
4import { DateTime } from "https://esm.sh/luxon@3.4.4";
56export async function testDailyBrief() {
7try {
8const testChatId = Deno.env.get("TEST_TELEGRAM_CHAT_ID");
2// Run this script manually to create the database table
34export default async function setupTelegramChatDb() {
5try {
6// Import SQLite module
stevensDemoRY65O7ZsendDailyBrief.ts6 matches
13} from "../memoryUtils.ts";
1415async function generateBriefingContent(anthropic, memories, today, isSunday) {
16try {
17const weekdaysHelp = generateWeekDays(today);
96}
9798export async function sendDailyBriefing(chatId?: string, today?: DateTime) {
99// Get API keys from environment
100const apiKey = Deno.env.get("ANTHROPIC_API_KEY");
135const lastSunday = today.startOf("week").minus({ days: 1 });
136137// Fetch relevant memories using the utility function
138const memories = await getRelevantMemories();
139216}
217218function generateWeekDays(today) {
219let output = [];
220239// console.log(weekDays);
240241// Export a function that calls sendDailyBriefing with no parameters
242// This maintains backward compatibility with existing cron jobs
243export default async function (overrideToday?: DateTime) {
244return await sendDailyBriefing(undefined, overrideToday);
245}
stevensDemoRY65O7ZREADME.md2 matches
16In a normal server environment, you would likely use a middleware [like this one](https://hono.dev/docs/getting-started/nodejs#serve-static-files) to serve static files. Some frameworks or deployment platforms automatically make any content inside a `public/` folder public.
1718However in Val Town you need to handle this yourself, and it can be suprisingly difficult to read and serve files in a Val Town Project. This template uses helper functions from [stevekrouse/utils/serve-public](https://www.val.town/x/stevekrouse/utils/branch/main/code/serve-public/README.md), which handle reading project files in a way that will work across branches and forks, automatically transpiles typescript to javascript, and assigns content-types based on the file's extension.
1920### `index.html`
26## CRUD API Routes
2728This app has two CRUD API routes: for reading and inserting into the messages table. They both speak JSON, which is standard. They import their functions from `/backend/database/queries.ts`. These routes are called from the React app to refresh and update data.
2930## Errors
stevensDemoRY65O7ZREADME.md2 matches
45* `migrations.ts` - code to set up the database tables the app needs
6* `queries.ts` - functions to run queries against those tables, which are imported and used in the main Hono server in `/backend/index.ts`
78## Migrations
18The queries file is where running the migrations happen in this app. It'd also be reasonable for that to happen in index.ts, or as is said above, for that line to be commented out, and only run when actual changes are made to your database schema.
1920The queries file exports functions to get and write data. It relies on shared types and data imported from the `/shared` directory.