Skip to content

Commit

Permalink
revert jwt check in worker
Browse files Browse the repository at this point in the history
  • Loading branch information
lalalune committed Feb 8, 2024
1 parent c42db84 commit a51ca0a
Show file tree
Hide file tree
Showing 12 changed files with 4,146 additions and 9,524 deletions.
13,495 changes: 4,070 additions & 9,425 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions packages/agent/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
"jsnext:main": "dist/index.esm.js",
"types": "dist/index.d.ts",
"files": [
"dist",
"src"
"dist"
],
"exports": {
".": {
Expand Down
2 changes: 1 addition & 1 deletion packages/agent/src/agent/actions/profile.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import chalk from 'chalk'
import {parseJSONObjectFromText} from '../utils'
import {composeContext} from '../../lib/context'
import { Memory } from '@/lib'
import { Memory } from '../../lib'

const template = `You are writing a profile for {{senderName}} based on their existing profile and ongoing conversations.
Expand Down
2 changes: 1 addition & 1 deletion packages/agent/src/lib/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export class AgentRuntime {
],
}),
};
console.log('calling completion, the requestOptions is', requestOptions)

const response = await fetch(
`${this.serverUrl}/api/ai/chat/completions`,
requestOptions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ const useListenToMessagesChanges = ({ getRoomData }: Props) => {
async (payload) => {
// @ts-ignore
addNewCurrentRoomMessage({ newMessage: payload.new, supabase });
console.warn('skipping last read update')
// if (payload.new.room_id === currentRoom.roomData?.id) {
// const { error: lastReadError } = await supabase
// .from("participants")
Expand Down
2 changes: 0 additions & 2 deletions packages/app/src/Hooks/rooms/useLoadUnreadMessages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ const useLoadUnreadMessages = () => {
return;
}

console.log('data', data)

setUnreadMessages(data);

// eslint-disable-next-line react-hooks/exhaustive-deps
Expand Down
2 changes: 2 additions & 0 deletions packages/app/src/Hooks/rooms/useRoomData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ const useRoomData = ({ roomId }: Props) => {
usersTyping: [],
});

console.log('getting rooms', roomId)

const { error: roomDataError, data: roomDataReq } = await supabase
.from("rooms")
.select(
Expand Down
38 changes: 0 additions & 38 deletions packages/app/src/pages/app/Room/Messages/Messages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ const Messages = (): JSX.Element => {
user: { uid },
} = useGlobalStore();

const [lastMessageRead, setLastMessageRead] = useState<number | null>(null);
const [showLastReadLabel, setShowLastReadLabel] = useState(true);

useEffect(() => {
scrollToBottom();
}, [messages?.length]);
Expand All @@ -34,27 +31,8 @@ const Messages = (): JSX.Element => {
const me = roomParticipants.find(
(participant) => participant.user_id === uid,
);

if (me) {
setLastMessageRead(me.last_message_read);
}
}, [roomParticipants, uid, messages]);

useEffect(() => {
if (!lastMessageRead) {
return;
}

const timeout = setTimeout(() => {
setShowLastReadLabel(false);
}, 5000);

// eslint-disable-next-line consistent-return
return () => {
clearTimeout(timeout);
};
}, [lastMessageRead]);

if (isLoadingMessages) {
return (
<>
Expand Down Expand Up @@ -121,22 +99,6 @@ const Messages = (): JSX.Element => {
message={message}
/>
</motion.div>

<Collapse
in={
lastMessageRead === message.id &&
lastMessageRead !== messages[messages.length - 1].id &&
showLastReadLabel
}
>
<Divider
mt={10}
mb={20}
labelPosition="left"
label="NEW"
color="red"
/>
</Collapse>
</AnimatePresence>
</motion.div>
</div>
Expand Down
7 changes: 2 additions & 5 deletions packages/shell/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import commonjs from '@rollup/plugin-commonjs'
import resolve from '@rollup/plugin-node-resolve'
import replace from '@rollup/plugin-replace'
import typescript from '@rollup/plugin-typescript'
import {defineConfig} from 'rollup'
import {terser} from 'rollup-plugin-terser'
import pkg from './package.json'

/**
* Flag to indicate build of library
Expand All @@ -19,13 +16,13 @@ export default defineConfig([
],
output: [
{
file: pkg.main,
file: 'index',
format: 'cjs',
sourcemap: true,
exports: 'auto',
},
{
file: pkg.module,
file: 'index',
format: 'es',
sourcemap: true,
},
Expand Down
2 changes: 1 addition & 1 deletion packages/shell/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { createClient } from "@supabase/supabase-js";
import inquirer from 'inquirer';
import chalk from "chalk";
import readline from "readline";
import { AgentRuntime, initialize, onMessage, getGoals, createGoal, agentActions } from "@cojourney/agent";
import { AgentRuntime, initialize, onMessage, getGoals, createGoal, agentActions } from "@cojourney/agent/src/index";
import { defaultGoal } from "./defaultGoal";

// check for --debug flag in 'node example/terminal --debug'
Expand Down
3 changes: 3 additions & 0 deletions packages/site/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"noUnusedLocals": false,
"allowUnusedLabels": true,
"plugins": [
{
"name": "next"
}
],
"paths": {
"react": [ "./node_modules/@types/react" ],
"@/*": ["./src/*"]
}
},
Expand Down
113 changes: 65 additions & 48 deletions packages/worker/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,33 +76,29 @@ class Server {
try {
req.pathname = pathname;

const supabase = createClient(env.SUPABASE_URL, env.SUPABASE_SERVICE_API_KEY, {
auth: {
persistSession: false
}
});

console.log('auth header: ', req.headers.get('Authorization'))

const token = req.headers.get('Authorization') &&
req.headers.get('Authorization').replace('Bearer ', '');
// const supabase = createClient(env.SUPABASE_URL, env.SUPABASE_SERVICE_API_KEY, {
// auth: {
// persistSession: false
// }
// });

// const token = req.headers.get('Authorization') &&
// req.headers.get('Authorization').replace('Bearer ', '');

// const out = await jwt.decode(token)

if(!token) {
return new Response('Unauthorized: No bearer token', { status: 401 });
}

const out = await jwt.decode(token)

console.log('out', out)
// const userId = out?.payload?.sub || out?.payload?.id || out?.id;

const userId = out?.payload?.sub || out?.payload?.id || out?.id;
// if(!userId) {
// return new Response('Unauthorized', { status: 401 });
// }

if(!userId) {
return new Response('Unauthorized', { status: 401 });
}
// console.log('userId', userId)

return await fn({ req, env, match: matchUrl, host: matchHost, userId, supabase });
return await fn({ req, env, match: matchUrl, host: matchHost, userId: null, supabase: null });
} catch (err) {
console.log('erro', err)
return new Response(err, { status: 500 });
}
}
Expand All @@ -121,51 +117,72 @@ class Server {

const server = new Server();

const headers = [
{
"key": "Access-Control-Allow-Origin",
"value": "*"
},
{
"key": "Access-Control-Allow-Methods",
"value": "*"
},
{
"key": "Access-Control-Allow-Headers",
"value": "Authorization, Content-Type"
},
{
"key": "Access-Control-Expose-Headers",
"value": "*"
}
];
const headers = {
// 'Access-Control-Allow-Origin': '*',
// 'Access-Control-Allow-Methods': '*',
// 'Access-Control-Allow-Headers': '*',
}

server.registerHandler({
method: 'OPTIONS',
async fn({ req, env }) {
return new Response('', {
status: 200, // Ensure this is 200 OK
headers: {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS",
"Access-Control-Allow-Headers": "Content-Type, Authorization",
}
});
status: 200,
headers,
}
);
},
});

server.registerHandler({
regex: /^\/api\/ai\/((?:completions|chat|files|embeddings|images|audio|assistants|threads)(?:\/.*)?)/,
method: 'POST',
async fn({ req, env, match }) {
console.log('calling openai', env.OPENAI_API_KEY)
const headers = {
'Authorization': `Bearer ${env.OPENAI_API_KEY}`,
};
console.log('headers', headers)
let url = 'https://api.openai.com/v1';
console.log('url', url)
return await proxyPipeApi({ req, match, env, headers, url })
},
});

const defaultHeaders = [
{
"key": "Access-Control-Allow-Origin",
"value": "*"
},
{
"key": "Access-Control-Allow-Methods",
"value": "*"
},
{
"key": "Access-Control-Allow-Headers",
"value": "*"
},
{
"key": "Access-Control-Expose-Headers",
"value": "*"
},
{
"key": "Access-Control-Allow-Private-Network",
"value": "true"
},
{
"key": "Cross-Origin-Opener-Policy",
"value": "same-origin"
},
{
"key": "Cross-Origin-Embedder-Policy",
"value": "require-corp"
},
{
"key": "Cross-Origin-Resource-Policy",
"value": "cross-origin"
}
];

const proxyPipeApi = async ({ req, env, match, url, headers }) => {
try {
let sub = '';
Expand Down Expand Up @@ -224,7 +241,7 @@ export default {
};

function _setHeaders(res) {
for (const { key, value } of headers) {
for (const { key, value } of defaultHeaders) {
res.headers.append(key, value);
}
return res;
Expand Down

0 comments on commit a51ca0a

Please sign in to comment.