Skip to content

Commit

Permalink
Merge pull request #152 from MyLife-Services/150-address-login
Browse files Browse the repository at this point in the history
20240124 @Mookse
  • Loading branch information
Mookse authored Jan 25, 2024
2 parents 6c436df + a5b9227 commit 95c25f8
Show file tree
Hide file tree
Showing 9 changed files with 249 additions and 29 deletions.
1 change: 1 addition & 0 deletions inc/js/functions.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ function category(ctx){ // sets category for avatar
ctx.body = ctx.state.avatar.category
}
async function challenge(ctx){
if(!ctx.params.mid?.length) ctx.throw(400, `requires member id`)
ctx.body = await ctx.session.MemberSession.challengeAccess(ctx.request.body.passphrase)
}
async function chat(ctx){
Expand Down
5 changes: 2 additions & 3 deletions inc/js/mylife-agent-factory.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,8 @@ class AgentFactory extends EventEmitter{
)
return _bots
}
async challengeAccess(_passphrase){
// always look to server to challenge Access; this may remove need to bind
return await mDataservices.challengeAccess(this.mbr_id,_passphrase)
async challengeAccess(_mbr_id, _passphrase){
return await mDataservices.challengeAccess(_mbr_id, _passphrase)
}
async getAlert(_alert_id){
const _alert = _alerts.system.find(alert => alert.id === _alert_id)
Expand Down
7 changes: 3 additions & 4 deletions inc/js/mylife-datamanager.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { CosmosClient } from '@azure/cosmos'
import Config from './mylife-datasource-config.mjs'
import chalk from 'chalk'
import { _ } from 'ajv'
// define class
class Datamanager {
#containers
Expand Down Expand Up @@ -59,15 +60,13 @@ class Datamanager {
return this.#core?.resource
}
// public functions
async challengeAccess(_mbr_id,_passphrase){
// execute store procedure with passphrase and this mbr_id? yes, so won't be charged to user if bad password attempts
async challengeAccess(_mbr_id, _passphrase){
// in order to obscure passphrase, have db make comparison (could include flag for case insensitivity)
const challengeOptions = { partitionKey: _mbr_id }
// Execute the stored procedure
const { resource: _result } = await this.#containers['members']
.scripts
.storedProcedure('checkMemberPassphrase')
.execute(_mbr_id,_passphrase,true) // first parameter is partition key, second is passphrase, third is case sensitivity
.execute(_mbr_id, _passphrase, true) // first parameter is partition key, second is passphrase, third is case sensitivity
return _result
}
async deleteItem(_id) {}
Expand Down
3 changes: 2 additions & 1 deletion inc/js/routes.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ _Router.get('/status', status)
_Router.get('/privacy-policy', privacyPolicy)
_Router.get('/signup', status_signup)
_Router.post('/', chat)
_Router.post('/challenge', challenge)
_Router.post('/challenge/:mid', challenge)
_Router.post('/signup', signup)
/* api webhook routes */
_apiRouter.use(_tokenValidate)
Expand All @@ -50,6 +50,7 @@ _memberRouter.get('/bots', bots)
_memberRouter.get('/bots/:bid', bots)
_memberRouter.get('/contributions/', contributions)
_memberRouter.get('/contributions/:cid', contributions)
_memberRouter.get('/select', loginSelect)
_memberRouter.get('/upload', upload)
_memberRouter.post('/category', category)
_memberRouter.post('/', chat)
Expand Down
2 changes: 1 addition & 1 deletion inc/js/session.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class MylifeMemberSession extends EventEmitter {
async challengeAccess(_passphrase){
if(this.locked){
if(!this.challenge_id) return false // this.challenge_id imposed by :mid from route
if(!this.factory.challengeAccess(_passphrase)) return false // invalid passphrase, no access [converted in this build to local factory as it now has access to global datamanager to which it can pass the challenge request]
if(!await this.factory.challengeAccess(this.challenge_id, _passphrase)) return false // invalid passphrase, no access [converted in this build to local factory as it now has access to global datamanager to which it can pass the challenge request]
// init member
this.#locked = false
this.emit('member-unlocked', this.challenge_id)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "server.js",
"type": "module",
"scripts": {
"start": "node server.js",
"start": "dotenv -e .env node server.js",
"dev": "dotenv -e .env nodemon server.js"
},
"nodemonConfig": {
Expand Down
247 changes: 229 additions & 18 deletions views/README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,239 @@
# Maht Frontend Client
# MyLife Member Services Application

## Overview

This is the frontend client for Maht, a chatbot that uses GPT-3 to answer questions about MyLife. Of course, this could/should be swapped out with any evolving ui that makes sense from a personalization persepective.
### MyLife: Preserving Member Stories for Posterity

### Layout
MyLife is a groundbreaking initiative aimed at capturing and preserving the essence of human experiences for future generations. We believe in the power of personal stories, memories, and media to shape our understanding of the human condition. Our platform provides a unique, enduring, and internet-based solution for individuals to record and showcase their life stories.
Additionally, with a raft of bot-assistants, ranging from personal admin to creative writing assistance to health tracking and monitoring to much more, you have access to powerful intelligent tools to help you manage and create in your daily life.

Using `KOA-EJS` as the framework, so relying on folder `views` rendering out `layout.html` => `index.html`
#### Vision and Mission

-[basic koa walkthrough](https://www.youtube.com/watch?v=z84uTk5zmak&ab_channel=TraversyMedia)
- **Mission**: Committed to offering a durable, enduring, and free platform for collecting and showcasing individual stories, media, and memories. We create a living, evolving encyclopedia of our selves where experiences and memory can be shared to the degree we consent. We provide superintelligent workspaces to get all of your personal or public work to get done.
- **Vision**: To enable every individual to be remembered forever, sharing their passions, wisdom, and experiences with posterity. We strive to create Earth's Library of Humanity in the metaverse, preserving 21st-century experiences as a permanent record.

## Development
### MyLife Member Services

## UX suggestions
MyLife Member Services are currently in closed alpha, but rolling admission to the alpha is granted every Monday, and you can register for free either at [the MyLife website](https://humanremembranceproject.org) or [our GPT-Store](https://chat.openai.com/g/g-rEjoOt9hN-mylife). We cannot wait to be able to provide these services to every human on earth, as MyLife fundamentally believes that a smarter humanity that leverages smarter tools will become a safer, more secure, and more ethical humanity.

- Create a background video, or at least something that pulses while gpt is in operation, I.e., talking with server
- like gpt-3, create stream (also requires much backend) [ISSUE #1](https://github.com/MyLife-Services/mylife-maht/issues/1)
- buttons across as navigation for chat suggestions: [ISSUE #2](https://github.com/MyLife-Services/mylife-maht/issues/2)
- What is a digital self?
- Tell me about MyLife
- Who founded
- Mission
- Values
- logo for Maht
- incorporate logo for MyLife
#### Key Features

again, a lot of these structures would come from the GPT-2 instance as tokenized requests to pass to GPT-turbo
- **Personalized Experience**: Tailored tools for individual story creation and memorialization.
- **Community Engagement**: Opportunities for members to interact, contribute, and learn from each other.
- **Educational Resources**: Access to lectures, presentations, and initiatives focusing on posterity archiving.
- **Fundraising and Support**: Options for direct donations, member dues, and other forms of support to sustain the platform.

#### Goals and Values

- **Primary Goals**: Capture and preserve living stories and beliefs for posterity, providing an immortal legacy for every individual.
- **Ethical Aims**: Foster introspection, empathy, digital justice, and equity.
- **Values**: Emphasis on data dignity, consent, authenticity, and personal security.

## Table of Contents

- [Overview](#overview)
- [MyLife](#mylife-preserving-member-stories-for-posterity)
- [MyLife Member Services](#mylife-member-services)
- [Features](#features)
- [Getting Started](#getting-started)
- [Prerequisites](#prerequisites)
- [Installation](#installation)
- [Architecture](#architecture)
- [API Documentation](#api-documentation)
- [Appendix](#appendix)
- [License](#license)
- [Contact](#contact)
- [Notes](#appendix-notes)

## Features

The MyLife platform offers a comprehensive suite of services that leverage advanced AI technology to enhance digital experiences for its members. The key features and services available to MyLife members are as follows:

1. **AI-Avatars**
- Members can run a legion of AI-powered bots, customizable to their needs.
- These avatars can be tailored to reflect aspects of the member's personality or expertise.
- They use OpenAI's GPT technology, allowing them to perform a wide range of tasks.

2. **Bot Functionality**
- The platform offers various specialized bots, such as:
- Personal-Assistant-bot for daily tasks and calendaring.
- Biographer-bot for capturing and sharing personal stories and experiences.
- Health-bot for fitness and medication tracking.
- Finance-bot for financial management.
- Resume-bot for animating and presenting resumes or CVs.
- and many more!
- These bots can be customized and are capable of evolving with the member's needs.

3. **My Indiverse**:
- A creative platform where members can bring their imaginations to life.
- Members can create intelligent objects or art and design virtual worlds.
- This service encourages creativity and interaction within the MyLife network.

4. **Protected Web-Browsing**:
- Features a DOM-Agent that intelligently re-renders external assets based on consent preferences.
- Enhances online security and privacy for members.

5. **Full-Spectrum Permissioning**:
- Utilizes natural language processing to develop an array of consents and preferences.
- Allows members to control their public and private online presence.

6. **Technical Assistance Services**:
- Offers hosting opportunities for personalized digital spaces.
- Enables members to create themed networks or partner platforms.
- Members can extend the functionality of MyLife and contribute to the community.

7. **Contribution to My Indiverse**:
- A platform for members to showcase their creativity and contributions.
- Encourages fun, learning, and innovation.

8. **Platform Improvement Suggestions**:
- MyLife values member input for platform enhancement.
- Members can suggest improvements, reflecting the diverse needs of the community.

In summary, MyLife's Member Services are designed to provide a rich, interactive, and personalized digital experience, leveraging AI technology to meet a wide range of member needs and preferences. The platform's focus on creativity, customization, and member contribution makes it a unique space for personal and community growth.

## Getting Started

This guide will help you get the MyLife Member Services application up and running on either your local development machine or even a hosted member services solution. We'll walk you through setting up your environment, installing the necessary dependencies, and starting the application.

We do not yet have a team focused on local implementation details, and these instructions were only tested on VSCode running on a Windows 11 OS.

### Prerequisites

Before you begin, ensure you have the following installed on your machine:

- **Node.js**: The application is built on Node.js. You need Node.js installed to run the server. Download and install it from [nodejs.org](https://nodejs.org/).
- **npm (Node Package Manager)**: npm is used to manage the application's dependencies. npm is included with Node.js, so when you install Node.js, you automatically get npm installed on your computer.
- **Git**: Git is used for version control and is required to clone the repository. Install it from [git-scm.com](https://git-scm.com/).
- **IDE**: We recommend an Integrated Development Environment (IDE) to write and edit code, but also to host the MyLife Node.js server, we use Visual Studio Code.

### Installation

1. **Clone the repository**: First, clone the MyLife Member Services repository to your local machine using Git. Open your terminal, navigate to the directory where you want to store the project, and run:

```bash
git clone https://github.com/MyLife-Services/mylife-maht.git
cd mylife-maht
```

2. **Install dependencies**: Once you have the project on your machine, you need to install its dependencies. Run the following command in the root directory of the project:

```bash
npm install
```

This command reads the `package.json` file and installs all the required Node.js packages listed in it.

3. **Environment Setup**: The application requires an environment setup. Create a `.env` file in the root of your project and add the necessary environment variables. Refer to the provided `.env.example` file for required keys. MyLife plans to offer self-retrieval keys for any data transfers, but for the time being, if you wish to run a hosted solution for friends, family or other community congregation, you will have to be vetted internally by connectingm with our technical leads @stratfordCircle Steve Kenney or @Mookse Erik Jespersen also reachable at <mylife.president@gmail.com>.

4. **Run the application**: After installing the dependencies and setting up the environment, you can start the application.

- local development: runs nodemon that watches certain files for server reload

```bash
npm run dev
```

- hosted environment: when running your own server, you can shortcut with

```bash
npm start
```

This should start the server, typically on `http://localhost:3000`. Open a web browser and navigate to this URL to interact with the application.

Congratulations! You should now have the MyLife Member Services application running on your local machine. For further information on usage and development, refer to the subsequent sections of this README.

## Architecture

The architecture of MyLife Member Services is meant to be scalable from production-level down to self-hosting, an intended architectural feature of the platform, enabling anyone world-wide to host an instantiation of MyLife Services for a group or coalition of members, so long as those users are registered and validated within the mainframe itself.

MyLife itself is an open-source project and, aside from LLM technologies at the core of its intelligence, it is built on open-source technologies. This architecture integrates various technologies and npm packages, enabling a diverse set of functionalities such as member login, bot-legion capabilities, and session management.

### Core Architecture

1. **Server-Side Application**
- Built using Node.js, a powerful JavaScript runtime, to handle server-side operations.
- Utilizes Koa.js, a web framework for Node.js, which is known for its lightweight and modular nature. Koa's middleware stack flows in a stack-like manner, allowing for more expressive and robust server-side development.

2. **Data Handling and Services**
- The application uses Azure Cosmos DB and PostgreSQL databases for data management, as indicated in the `mylife-data-service.js` file.
- It employs a data service layer (`Dataservices` class) to manage interactions with the data layers, offering methods for CRUD operations, handling avatars, bots, alerts, and other core elements.

3. **Bot Functionality and Intelligence Management**
- The application features a sophisticated bot system, capable of creating and managing different types of bots like personal assistants, biographers, health bots, etc.
- OpenAI's GPT-3 model is integrated for generating responses and interacting with users through bots, as observed in the `class-avatar-functions.mjs` and `mylife-agent-factory.mjs` files.
4. **Session Management**
- Managed through the `MylifeMemberSession` class, handling user sessions, consents, and alerts.
- Utilizes EventEmitter for managing and emitting custom events.
5. **Routing and API Handling**
- The system uses Koa Router for handling HTTP requests, defining routes for various functionalities like member access, bot activation, and content contributions.
6. **Front-End Interaction**
- The system leverages an EJS front-end page view system
- Core functionality executed through REST endpoints
- CSS relies on flex, bootstrap and font-awesome
### NPM Packages and Dependencies
1. **Core Dependencies**
- `koa` and related packages (`koa-router`, `koa-static`, `koa-body`, etc.) for web server framework.
- `openai` for integrating OpenAI's GPT models.
- `azure/cosmos` and `pg` for interacting with Azure Cosmos DB and PostgreSQL databases.
- `events` for event emission handling.
- `chalk` for terminal string styling.

2. **Utilities and Helpers**
- `ajv` for JSON schema validation.
- `js-guid` for GUID generation.
- `marked` for markdown parsing.

3. **Development Tools**
- `eslint` for code linting.
- `nodemon` for automatically restarting the node application when file changes are detected.

4. **Miscellaneous**
- `url`, `path`, `fs`, `util`, and other Node.js built-in modules for various utility functions.

## API Documentation

While API interactions could certainly be divined by code review, we have currently not pointed an intelligence at it, but it will arrive soon.

## Appendix

### License

This project is licensed under the MIT License - see the [LICENSE](#mit-license) file for details.

#### MIT License

Copyright (c) 2024 [MyLife](https://humanremembranceproject.org)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

### Contact

You may contact either Erik Jespersen @Mookse or Steve Kenney @stratfordCircle at github with any technical questions.
Additionally, you could visit the main [MyLife website](https://humanremembranceproject.org) at <mylife.president@gmail.com>.

### Appendix Notes

- add resources/references section to this document
8 changes: 8 additions & 0 deletions views/assets/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@ body {
color: #ffffff; /* White text for better readability */
margin-left: 0;
}
.agent-bubble a {
font-size: 1em;
color: #dcb6ff; /* White text for better readability */
}
.button.chat-submit {
flex: 0 0 auto;
color: rgba(65, 84, 104, 0.85);
Expand Down Expand Up @@ -367,9 +371,13 @@ body {
.member-bubble, .user-bubble {
background-color: rgba(225, 245, 254, 1); /* A light shade of blue for the user */
color: #333333; /* Dark grey for contrast and easy reading */
font-size: .75em;
margin-left: auto;
margin-right: 12px;
}
.member-bubble a, .user-bubble a {
color: #333333; /* Dark grey for contrast and easy reading */
}
#message {
margin-right: 0.5rem;
}
Expand Down
3 changes: 2 additions & 1 deletion views/members-challenge.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
const _passphrase = document.getElementById('member-challenge').value;
if(!_passphrase.length) return
// test passphrase against url
const url = window.location.origin+'/challenge';
const _mbr_id = window.location.pathname.split('/')[window.location.pathname.split('/').length-1]
const url = window.location.origin+`/challenge/${_mbr_id}`;
const options = {
method: 'POST',
headers: {
Expand Down

0 comments on commit 95c25f8

Please sign in to comment.