Skip to content

Commit

Permalink
fix native build
Browse files Browse the repository at this point in the history
  • Loading branch information
lalalune committed Feb 7, 2024
1 parent b73a9a3 commit 4f9e2de
Show file tree
Hide file tree
Showing 14 changed files with 84 additions and 197 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,21 @@ More to come, watch this space!

```bash
yarn install
yarn build # build the packages at least once
```

## Usage

To start everything
```bash
yarn run dev
# App: http://localhost:3000
# Site: http://localhost:3001
# Docs: http://localhost:3002
# API: http://localhost:7998
```

Once you've started everything, you can talk to CJ, the default agent, by running the terminal:
```bash
yarn run cj
```
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
"scripts": {
"dev": "workspaces-run --parallel -- npm run dev",
"dev:terminal": "cd packages/terminal && yarn run dev",
"cj": "cd packages/terminal && yarn run dev:terminal",
"build": "npm run build --workspaces --if-present",
"test": "npm test --workspaces --if-present",
"coverage": "npm run coverage --workspaces --if-present",
Expand Down
14 changes: 2 additions & 12 deletions packages/agent/src/agent/actions/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@ Then respond with a JSON object containing a field for description in a JSON blo
Your response must include the JSON block.`

const handler = async (message: any, state: any, runtime: any) => {
console.log('profile update message', message)

console.log('state is', state)

const handler = async (_message: any, state: any, runtime: any) => {
//

// TODO:
Expand Down Expand Up @@ -86,23 +82,17 @@ const handler = async (message: any, state: any, runtime: any) => {
.single();
const { data: relationshipRecord, error: error2 } = response2;
if(error2) {
console.error('error getting relationship', error2)
return
}

console.log('relationshipRecord is', relationshipRecord)

console.log('userRecord is', userRecord)

const descriptionMemory = new Memory({
user_ids: [state.agentId, userRecord.id],
user_id: state.agentId,
content: description,
room_id: relationshipRecord.room_id,
})
console.log('descriptionMemory', descriptionMemory.toJSON())

await runtime.descriptionManager.upsertRawMemory(descriptionMemory);
console.log('stored descriptionMemory', descriptionMemory)
} else if (runtime.debugMode) {
console.log(chalk.red('Could not parse response'))
}
Expand Down
7 changes: 1 addition & 6 deletions packages/agent/src/agent/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,10 @@ export const onMessage = async (message: any, runtime: any) => {
}
// if the last two messages had the WAIT action from current agent, then we should skip
const lastTwoMessagesFromAgent = lastThreeMessagesFromAgent.slice(-2)
console.log('lastTwoMessagesFromAgent', lastTwoMessagesFromAgent)
const lastTwoMessagesFromAgentWithWaitAction =
lastTwoMessagesFromAgent.filter(
(message: any) => message.content.action === 'WAIT'
)
console.log(
'lastTwoMessagesFromAgentWithWaitAction',
lastTwoMessagesFromAgentWithWaitAction
)
if (lastTwoMessagesFromAgentWithWaitAction.length === 2) {
return console.log(
'Skipping because last two messages from agent had WAIT action'
Expand Down Expand Up @@ -240,7 +235,7 @@ export const onMessage = async (message: any, runtime: any) => {
.find((a: {name: any}) => a.name === data.action)

if (!action) {
return console.warn('No action found for', data.action)
return // console.warn('No action found for', data.action)
}

if (!action.handler) {
Expand Down
24 changes: 23 additions & 1 deletion packages/app-native/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,26 @@
{
"files": [],
"compilerOptions": {
"target": "ESNext",
"useDefineForClassFields": true,
"lib": ["DOM", "DOM.Iterable", "ESNext"],
"allowJs": false,
"skipLibCheck": true,
"esModuleInterop": false,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "ESNext",
"moduleResolution": "Node",
"resolveJsonModule": true,
"isolatedModules": true,
"noUnusedLocals": false,
"allowUnusedLabels": true,
"noEmit": true,
"jsx": "react",
"paths": {
"react": [ "./node_modules/@types/react" ],
}
},
"include": ["src"],
"references": [{ "path": "./tsconfig.node.json" }, { "path": "./tsconfig.web.json" }]
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ const useHandleFriendsRequests = () => {

const handleSendFriendRequest = async ({
friendId,
friendEmail,
}: ISendFriendRequest): Promise<void> => {
setIsLoading(true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const UploadProfileImage = ({
maxSize={3 * 1024 ** 2}
multiple={false}
onDrop={(files): void => {
setImage(files[0]);
setImage(files[0] as any);
}}
onReject={(): void => {
showNotification({
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/components/RegisterUser/steps/step2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const Step2 = ({ prevStep }: IStepProps): JSX.Element => {
});
}

let IMAGE_URL = null;
let IMAGE_URL = "";

if (profileImage) {
const { data: imageUploadData, error } = await supabase.storage
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/components/UserPopup/UserPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interface Props {
};
}

const UserPopup = ({ user, children }: Props): JSX.Element => {
const UserPopup = ({ children }: Props): JSX.Element => {
const {
relationships: { friends },
setApp,
Expand Down
2 changes: 1 addition & 1 deletion packages/terminal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"sideEffects": false,
"scripts": {
"dev": "rollup -c -w",
"dev:terminal": "node --no-warnings terminal.mjs",
"dev:terminal": "yarn run build && node --no-warnings terminal.mjs",
"build": "rollup -c && tsc --declaration --emitDeclarationOnly --declarationDir dist",
"build:types": "tsc --declaration --emitDeclarationOnly --declarationDir dist",
"test": "jest",
Expand Down
140 changes: 0 additions & 140 deletions packages/terminal/src/index.js

This file was deleted.

29 changes: 19 additions & 10 deletions packages/terminal/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ const getSupabase = (access_token?: string) => {
}

export const getMe = async (session: { access_token: string | undefined }) => {
console.log(session)
const { data: { user }, error} = await getSupabase(session.access_token).auth.getUser()
if (error) {
console.log(error)
await getSupabase(session.access_token).auth.signOut();
console.log('*** error', error)
return null;
} else {
return user;
Expand All @@ -65,14 +65,13 @@ export const getMe = async (session: { access_token: string | undefined }) => {

// Main application logic
// Main application logic
async function startApplication(_supabase?: any) {
async function startApplication() {
console.log(chalk.green('Starting application...'));

// Assuming session information is stored in the .cjrc file
const userData = JSON.parse(fs.readFileSync(configFile).toString());
const session = userData?.session;
console.log('session.access_token', session.access_token)
const supabase = _supabase ?? getSupabase(session.access_token);
const supabase = getSupabase(session.access_token);
let user = null as any;
if (session) {
// Get user information or perform any other session-related initialization here
Expand Down Expand Up @@ -219,8 +218,17 @@ function setupReadlineAndMessageLoop(runtime: AgentRuntime, room_id: any, agentI

// Function to handle user login or signup
async function handleUserInteraction() {
if (!fs.existsSync(configFile)) {
console.log(chalk.yellow('No configuration file found. Please log in or sign up.'));
let user;

if(fs.existsSync(configFile)){
// try to read the file as json
const userData = JSON.parse(fs.readFileSync(configFile).toString());
const session = userData?.session;
user = await getMe(session);
}

if (!user) {
console.log(chalk.yellow('Please log in or sign up.'));
const { action } = await inquirer.prompt([{
type: 'list',
name: 'action',
Expand All @@ -236,6 +244,9 @@ async function handleUserInteraction() {
} else {
console.log(chalk.green('Configuration file found. You are already logged in.'));
await startApplication(); // Start the application if already logged in



}
}

Expand Down Expand Up @@ -264,13 +275,11 @@ async function loginUser() {
password: credentials.password,
});

console.log('data', data)

if (error) throw error;

fs.writeFileSync(configFile, JSON.stringify({ session: data.session }));
console.log(chalk.green('Login successful! Configuration saved.'));
await startApplication(supabase); // Start the application after login
await startApplication(); // Start the application after login
} catch (error: any) {
console.error(chalk.red(`Login failed: ${error.message}`));
}
Expand Down
7 changes: 0 additions & 7 deletions tsconfig.json

This file was deleted.

Loading

0 comments on commit 4f9e2de

Please sign in to comment.