Skip to content

Commit

Permalink
asdfdf
Browse files Browse the repository at this point in the history
  • Loading branch information
adnan wahab committed Oct 19, 2024
1 parent a393761 commit f7e6e48
Show file tree
Hide file tree
Showing 3 changed files with 185 additions and 20 deletions.
53 changes: 37 additions & 16 deletions scripts/infra/caddy/Caddyfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,29 @@ hashirama.blog {
reverse_proxy localhost:8080
}

route /cgi-tools/* {
reverse_proxy localhost:8004
# route /cgi-tools/* {
# reverse_proxy localhost:8004
# }

route /ws/* {
reverse_proxy localhost:8080 {
transport http {
# Allow WebSocket upgrades
versions h2c 1.1
}
}
}

route /infra-tools/* {
respond "ok"
}

route /llama-tools/* {
reverse_proxy localhost:8003
route /robotics-tools/* {
respond "ok"
}

route /science-tools/* {
respond "ok"
}

route /health {
Expand Down Expand Up @@ -65,6 +82,10 @@ hashirama.blog {
reverse_proxy localhost:2283
}

# route /ws/* {
# reverse_proxy localhost:8080
# }

respond "404 Not Found" 404

header Access-Control-Allow-Origin *
Expand Down Expand Up @@ -93,15 +114,15 @@ jupyter.hashirama.blog {
reverse_proxy localhost:8888
}

# llama-tools.com {
# tls {
# dns porkbun pk1_db81d4b3634b90e44327d0d42d7fd5f46e3ca439a2ffe2587cd6a91ff9835aa3 sk1_dedb9466f623f54c717975473ac5c14a8a544f0a07b2f1266de20e55ffeafc70
# }
## /cgi/* {
# reverse proxy to flux
# }

# header Access-Control-Allow-Origin *
# header Access-Control-Allow-Methods "GET, POST, OPTIONS"
# header Access-Control-Allow-Headers "Content-Type"
# }
llama-tools.com {
tls {
dns porkbun pk1_db81d4b3634b90e44327d0d42d7fd5f46e3ca439a2ffe2587cd6a91ff9835aa3 sk1_dedb9466f623f54c717975473ac5c14a8a544f0a07b2f1266de20e55ffeafc70
}
# /cgi/* {
#reverse proxy to flux
respond "llama-tools"

header Access-Control-Allow-Origin *
header Access-Control-Allow-Methods "GET, POST, OPTIONS"
header Access-Control-Allow-Headers "Content-Type"
}
117 changes: 113 additions & 4 deletions web-ui/js/course_handler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import serveMakeBunCell from './bun_helper.ts'
import docker_run from './docker_helper.ts'
import llamaRoutes from './bun_handlers/llama-backend.jsx'
import CgiRoutes from './bun_handlers/cgi-backend.js'
import Bun from 'bun'
// doc = https://caddyserver.com/docs/

function serveLlamaTools(req: Request) {
Expand Down Expand Up @@ -56,7 +57,34 @@ function serveOptimizelyPlaywrightSupervision() {

}

// const WebSocket = require('ws');
// const fs = require('fs');

// const wss = new WebSocket.Server({ port: 8080 });

// wss.on('connection', (ws) => {
// ws.on('message', (message) => {
// const data = JSON.parse(message);
// fs.writeFileSync('data.json', JSON.stringify(data, null, 2));
// ws.send('Data saved successfully');
// });
// });


//Response.json
// return new Response(file("index.html"));
// return Response.redirect("/redirected");


const save_livekit_data = (req: Request) => {
const data = req.body;
Bun.write('data.json', JSON.stringify(data, null, 2));
return new Response('Data saved successfully', { status: 200 });
}

const routes = {
"/serve_proxy_docs": (req: Request) => serve_proxy_docs(req),
"/save-livekit-data": (req: Request) => save_livekit_data(req),
//"/": (req: Request) => make_docs,
"docs/": (req: Request) => response_404(req),
"_outlier_agent": (req: Request) => serveOutlierAgent(req),
Expand Down Expand Up @@ -128,24 +156,102 @@ const response_404 = () => {
//return response_404(routes)


const proxy_docs = [
"https://bun.sh/docs/runtime/bunfig#run-bun-auto-alias-node-to-bun",
//"https://google.com",
//"https://youtube.com",
//"https://github.com",
//"https://openai.com",
//"https://bun.sh/docs",
"https://zed.dev/docs/multibuffers",
]

function serve_proxy_docs(req: Request) {
const html_string = proxy_docs.map(doc => `<div><iframe src=${"/proxy/" + doc}></iframe></div>`).join("\n")
console.log('html_string', html_string)

return new Response(html_string, {
headers: {
"Content-Type": "text/html",
},
});
}


async function proxy(req: Request) {
const url = new URL(req.url);
console.log('url', url.pathname)
if (routes[url.pathname]) {


if (routes[url.pathname]) { //handles all HTTPS JSON regular bear routes
return routes[url.pathname](req)
}
return response_404(req)




console.log('url.pathname', url.pathname, url.pathname.startsWith("/proxy"))
//llama in the request handler ?!??!?!
if (url.pathname.startsWith("/proxy")) {
const targetUrl = url.pathname.replace("/proxy", "");
if (targetUrl === "") {
return new Response("how to proxy??? - try /proxy/https://google.com", {
headers: {
"Content-Type": "text/html",
},
});
}
console.log('targetUrl', targetUrl)

const response = await fetch("https://bun.sh", {
method: req.method,
headers: req.headers,
body: req.body,
});

return new Response(response.body)
// return new Response(response.body, {
// status: response.status,
// statusText: response.statusText,
// headers: response.headers,
// });





// const response = await fetch(targetUrl, {
// method: req.method,
// headers: req.headers,
// body: req.body,
// });
// return new Response(response.body, {
// status: response.status,
// statusText: response.statusText,
// headers: response.headers,
// });
}


//return response_404(req)
}

// (nanosaur factory)
// peteer attia - rhonda patrick ----- bill nye

const handle_websocket = (ws: WebSocket) => {
ws.on('message', (message) => {
console.log('message', message)
})
}


const port = 8080;
async function main() {
serve({
Bun.serve({
port,
fetch: proxy,
// websocket: handle_websocket
});
}
console.log('compile time checks: ' ,'typeof default_response === string' , typeof default_response === 'string');
Expand Down Expand Up @@ -234,4 +340,7 @@ let indexHtmlContent = fs.readFileSync(filePath, "utf-8");
}

//tic tac toe not stephane and anyone who blah -> they have to recruit the most knowleable they know
// iq lead weight , hardw ork = gem stones ?
// iq lead weight , hardw ork = gem stones ?

///robots nee dt o browweserewb - how else will they know when law changes a --- are they suppseod to wait for some guy to look it up and doit ?!?!?!
// geofences shure but what about liek what kylge
35 changes: 35 additions & 0 deletions web-ui/views/llama-tools/livekit_speech_to_fn_call.html
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,41 @@
document.body.addEventListener("click", () => {
startLiveKit();
});


// const socket = new WebSocket('ws://hashirama.blog/ws/');

// socket.addEventListener('open', () => {
// socket.send(JSON.stringify(data));
// });

// socket.addEventListener('message', (event) => {
// console.log('Message from server ', event.data);
// });

async function sendDataToServer(data) {
try {
const response = await fetch('/save-data', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(data),
});

if (!response.ok) {
throw new Error('Failed to send data to server');
}

console.log('Data successfully sent to server');
} catch (error) {
console.error('Error:', error);
}
}




</script>
</body>
</html>

0 comments on commit f7e6e48

Please sign in to comment.