3import { updateThreadName } from "../database/queries.ts";
45export async function generateThreadName(apiKey, firstMessage, anthropicApiKey) {
6const anthropic = createAnthropic({
7apiKey,
5const CACHE_WRITE_RATE = 3.75; // $3.75 per M cache-write tokens :contentReference[oaicite:3]{index=3}
67export function calculateCost({
8input_tokens,
9completed_tokens,
live-reloadutils.ts8 matches
12* @throws {Error} If the specified branch is not found
13*/
14export async function getProjectIds(importMetaUrl: string) {
15const {
16name: projectName,
28}
2930async function projectLastUpdated({ project_id, branch_id }: { project_id: string; branch_id: string }) {
31const { updatedAt, version } = await client.projects.branches.retrieve(
32project_id,
36}
3738async function wait(ms: number) {
39return new Promise(resolve => setTimeout(resolve, ms));
40}
49* @returns {Promise} A new promise with timeout behavior
50*/
51export function timeout<T>(
52promise: Promise<T>,
53timeoutMs: number,
66}
6768export async function longPollLastUpdated({
69version,
70project_id,
98* the full text response.
99*
100* @param handler The original fetch handler function
101* @param html The HTML content to inject
102* @returns A new fetch handler with HTML rewriting
103*/
104export function injectHTML(
105handler: (request: Request) => Promise<Response>,
106html: string,
112}
113114export async function injectHTMLResponse(
115response: Response,
116html: string,
3import React, { useState } from "https://esm.sh/react@18.2.0";
45function App() {
6const [file, setFile] = useState<File | null>(null);
7const [feedback, setFeedback] = useState<string | null>(null);
117};
118119function client() {
120createRoot(document.getElementById("root")).render(<App />);
121}
122if (typeof document !== "undefined") { client(); }
123124export default async function server(request: Request): Promise<Response> {
125if (request.method === "POST") {
126try {
sqliteExplorerAppREADME.md1 match
33- [x] fix wonky sidebar separator height problem (thanks to @stevekrouse)
34- [x] make result tables scrollable
35- [x] add export to CSV, and JSON (CSV and JSON helper functions written in [this val](https://www.val.town/v/nbbaier/sqliteExportHelpers). Thanks to @pomdtr for merging the initial version!)
36- [x] add listener for cmd+enter to submit query
25mandateId: string;
26taskId: string;
27log: LogFunction;
28// Could add other shared resources here (e.g., config, shared memory access)
29}
3031/** Defines the function signature for any agent. */
32type AgentFunction<InputPayload = any, OutputPayload = any> = (
33input: AgentInput<InputPayload>,
34context: AgentContext,
73// --- Logging ---
7475type LogFunction = (level: LogLevel, component: string, message: string, details?: any) => void;
76type LogLevel = "DEBUG" | "INFO" | "WARN" | "ERROR" | "SUCCESS";
77101}
102103createLogFunction(mandateId: string, baseComponent?: string): LogFunction {
104return (level, component, message, details) => {
105const entry: Omit<LogEntry, 'timestamp' | 'taskId'> = {
132133class AgentRegistry {
134private agents: Map<string, AgentFunction<any, any>> = new Map();
135136register<InputPayload, OutputPayload>(
137name: string,
138agentFn: AgentFunction<InputPayload, OutputPayload>,
139): void {
140if (this.agents.has(name)) {
145}
146147getAgent(name: string): AgentFunction<any, any> | undefined {
148return this.agents.get(name);
149}
174): Promise<WorkflowResult<FinalPayload>> {
175const mandateId = `M-${Date.now()}-${definition.id}`;
176const log = this.logger.createLogFunction(mandateId, 'WorkflowEngine');
177const stepResults = new Map<string, AgentOutput<any>>(); // Store outputs of successful steps
178272273// Agent 1: Summarizer (modified for new signature)
274async function summarizerAgent(
275input: AgentInput<{ textToSummarize: string }>,
276context: AgentContext,
297298// Agent 2: Fetch External Data (modified for new signature)
299async function fetchAgent(
300input: AgentInput<{ url?: string }>, // Optionally allow URL via input
301context: AgentContext,
362// agentRegistry.register("sentimentAnalyzer", sentimentAgent);
363364function generateHtmlShell() {
365// Same HTML shell as before - no changes needed here
366return `<!DOCTYPE html>
446447// Val Town Entry Point (or adapt for Node.js/Deno/Bun)
448export default async function(req: Request): Promise<Response> {
449// Clear logs for each new request to avoid mixing logs between runs
450globalLogger.clear();
hn_job_analyzerhnService.ts11 matches
1export async function fetchHiringPosts(postId?: number): Promise<any[]> {
2try {
3// If no post ID is provided, find the latest "Who is hiring" post
24}
2526export async function fetchWantToBeHiredPosts(postId?: number): Promise<any[]> {
27try {
28// If no post ID is provided, find the latest "Who wants to be hired" post
49}
5051export async function fetchFreelancerPosts(postId?: number): Promise<any[]> {
52try {
53// If no post ID is provided, find the latest "Freelancer? Seeking Freelancer?" post
74}
7576// Helper function to fetch an item from the HN API
77async function fetchItem(id: number): Promise<any> {
78const response = await fetch(`https://hacker-news.firebaseio.com/v0/item/${id}.json`);
79return await response.json();
80}
8182// Helper function to find the latest "Who is hiring" post
83async function findLatestHiringPostId(): Promise<number> {
84try {
85// First, get the latest stories
112}
113114// Helper function to find the latest "Who wants to be hired" post
115async function findLatestWantToBeHiredPostId(): Promise<number> {
116try {
117// First, get the latest stories
144}
145146// Helper function to find the latest "Freelancer? Seeking Freelancer?" post
147async function findLatestFreelancerPostId(): Promise<number> {
148try {
149// First, get the latest stories
hn_job_analyzeraiAnalyzer.ts4 matches
8});
910// Function to analyze job opportunities
11export async function analyzeJobOpportunities(hiringPosts: any[], freelancerPosts: any[], resumeData: any): Promise<string> {
12try {
13// Prepare content for analysis
53}
5455// Function to analyze competition
56export async function analyzeCompetition(wantToBeHiredPosts: any[], freelancerPosts: any[], resumeData: any): Promise<string> {
57try {
58// Prepare content for analysis
hn_job_analyzerutils.ts4 matches
1export function formatDate(date: Date): string {
2return date.toISOString().split('T')[0];
3}
45export function getCurrentMonth(): string {
6const months = [
7'January', 'February', 'March', 'April', 'May', 'June',
13}
1415export function getCurrentYear(): number {
16return new Date().getFullYear();
17}
1819export function sanitizeHTML(text: string): string {
20return text
21.replace(/&/g, '&')
discord-botapi-server.js4 matches
1516/**
17* Function to analyze messages with OpenAI
18* @param {Array} messages - Array of message objects
19* @param {string} query - User query to analyze messages with
20* @returns {Object} - OpenAI response
21*/
22async function analyzeMessagesWithAI(messages, query) {
23try {
24// Format messages for OpenAI
179180/**
181* Val.town handler function for HTTP requests
182* This will be exposed as a Val.town HTTP endpoint
183*/
184export default async function handler(req, res) {
185// Create a simple adapter to route the request through Express
186return new Promise((resolve, reject) => {