Skip to content

Commit

Permalink
Merge pull request #112 from MyLife-Services/azure-base-prune
Browse files Browse the repository at this point in the history
Version 0.0.1.0063
  • Loading branch information
Mookse authored Jan 2, 2024
2 parents 8d4915d + 43bc846 commit dbce4b3
Show file tree
Hide file tree
Showing 58 changed files with 5,511 additions and 1,506 deletions.
12 changes: 12 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Ignore files that are already ignored by git
.gitignore
# Ignore files that are specific to your development environment
.git
.env
postman
.postman
.vscode
.github
# Ignore docker-specific files
.dockerignore
Dockerfile
14 changes: 11 additions & 3 deletions .env-sample
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
OPENAI_API_KEY={ your individual openai API key -- see instructions}
OPENAI_BASE_URL=https://api.openai.com/v1
OPENAI_MAHT_GITHUB=https://github.com/MyLife-Services/mylife-maht.git
OPENAI_MAX_TOKENS={ see max tokens }
OPENAI_MODEL_CORE="gpt-3.5-turbo"
OPENAI_ORG_KEY={ use ours or use your own }
OPENAI_TEMP={ temp }
OPENAI_TIMEOUT={ timeout }
PORT={ KOA port }
MYLIFE_ALLOW_INTELLIGENT_QUESTIONS=false
MYLIFE_DB_ALLOW_SAVE=true
MYLIFE_DB_ENDPOINT={ get from administrator }
MYLIFE_DB_NAME={ get from administrator }
MYLIFE_DB_RW={ get from administrator }
Expand All @@ -15,4 +16,11 @@ MYLIFE_SERVER_MBR_ID={ get Maht info from administrator or request own }
MYLIFE_HOSTED_MBR_ID=["mbr_id's hosted by this server"]
MYLIFE_SESSION_KEY={ type in own personal key, quoted or unquoted if no spaces... Restarting server will NOT refresh sessions (as of now) so must change this key to refresh server-level constants}
MYLIFE_SESSION_TIMEOUT_MS={ session timeout in milliseconds }
MYLIFE_VERSION=1.0
MYLIFE_VERSION=1.0
MYLIFE_EMBEDDING_SERVER_URL=http://mylife-embedding-server
MYLIFE_EMBEDDING_SERVER_PORT=8000
MYLIFE_EMBEDDING_SERVER_BEARER_TOKEN={ chosen personally to match environment variable in embedding server }
MYLIFE_EMBEDDING_SERVER_FILESIZE_LIMIT={ filesize } # 1MB = 1024 * 1024
MYLIFE_EMBEDDING_SERVER_FILESIZE_LIMIT_ADMIN={ filesize } # 10MB = 1024 * 1024 * 10
MYLIFE_CONTRIBUTIONS_DB_CONTAINER_NAME={ get from administrator }
MYLIFE_REGISTRATION_DB_CONTAINER_NAME={ get from administrator }
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# basic js installations
package-lock.json
/node_modules/
/in-progress/
.env*
.vscode/
__*/ # ignore all folders starting with an underscore
__*/ # ignore all folders starting with an underscore
.hintrc
.uploads
.tmp
.DS_Store
.code-workspace
11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

FROM node:14

WORKDIR /app
COPY . /app

RUN npm install

EXPOSE 3000

CMD ["npm", "run", "start"]
97 changes: 72 additions & 25 deletions README.md

Large diffs are not rendered by default.

69 changes: 69 additions & 0 deletions inc/js/agents/system/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# MyLife System Assistants

The MyLife system incorporates a suite of specialized assistants, each designed to augment various aspects of the avatars within the platform. These assistants follow consistent coding protocols and are currently intended exclusively for integration with avatars, enhancing their functionality and interactivity.

- **Asset-Assistant (File Handler)**: This assistant manages file-related operations, ensuring efficient handling, storage, and retrieval of files within the system. It acts as a central hub for file management tasks, streamlining the process of dealing with various file formats and data types.

- **Evolution-Assistant**: Central to the avatar's developmental journey, the Evolution Assistant orchestrates the growth and maturation of avatars. It guides avatars through different phases of evolution, from creation to retirement, tailoring the development process according to the avatar's specific needs and contexts.

- **DOM-Assistant**: The Document Object Model (DOM) Assistant is pivotal in managing and manipulating the structure of data and documents within the system. It plays a key role in ensuring the data is organized and accessible in a way that is both efficient and intuitive.

- **Preferences-Assistant**: This assistant is dedicated to personalizing user experiences by managing and adapting to user preferences. It ensures that avatars can cater to individual tastes and requirements, making interactions more tailored and relevant.

- **Settings-Assistant**: Focused on configuration management, the Settings Assistant allows for the customization and adjustment of system settings. This ensures that avatars can operate within the parameters that best suit the user's needs and the system's operational environment.

- **Connector-Assistant (External Service Manager)**: Acting as a bridge to the outside world, the Connector Assistant manages interactions with external services and platforms. Whether it's cloud services, music, information databases, or external avatar services, this assistant facilitates seamless integration and interaction with a variety of external resources and services.

Each of these assistants contributes to a more dynamic, efficient, and personalized avatar experience within the MyLife system. By specializing in different domains, they collectively enhance the overall functionality and adaptability of the avatars, making them more capable and versatile in serving the users' diverse needs.

## Evolution Assistant (Evo-Agent)

### Overview

The Evolution Assistant, referred to as Evo-Agent, is a core component in the MyLife asset-assistant project. It is implemented in the `evolution-assistant.mjs` file and serves as an integral part of the system, managing the evolutionary process of avatars within the MyLife platform.

### Design and Functionality

- **Class Definition**: `EvolutionAssistant` class extends `EventEmitter`.
- **Private Members**:
- `#avatar`: A reference to the symbiotic avatar object.
- `#contributions`: An array to manage contributions related to the avatar.
- `#phase`: Tracks the current phase of evolution, such as 'create', 'init', 'develop', etc.
- **Constructor**:
- Initializes the Evo-Agent with a default phase and binds it to a specific avatar.
- **Key Methods**:
- `init()`: Initializes the Evo-Agent, setting up initial contributions.
- `avatar()`, `being()`, `categories()`, etc.: Getters for various avatar properties.
- `#advancePhase()`: A private method to advance the evolutionary phase of the avatar.

### Event Handling

The Evo-Agent is designed to emit events at different stages of its lifecycle, signaling the beginning and completion of various phases. It leverages Node.js's `EventEmitter` for event-driven programming.

### Modular Design

The codebase follows a modular approach, with functions like `mAdvancePhase()` and `mAssessData()` externalized for specific operations, maintaining a clean and manageable structure.

### Phases of Evolution

The Evo-Agent guides the avatar through multiple phases:

- `create`
- `init`
- `develop`
- `mature`
- `maintain`
- `retire`

Each phase has specific goals and criteria, ensuring a comprehensive and dynamic evolution process for the avatar.

### Contribution Management

The Evo-Agent actively manages contributions that aid in the growth and development of the avatar. It assesses and selects categories most in need of contributions, facilitating continuous evolution.

## Appendix

### Notes

modular assistants, not actual agents, but system functionality that can be used _by_ agents
all outputs thereby should be in the form of a consistent class, that is at least initially defined by the global config at its heart (i.e., inclusive at least, if one-day not fully birthed from, the raw json config file)
125 changes: 125 additions & 0 deletions inc/js/agents/system/asset-assistant.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
// imports
import fs from 'fs'
import mime from 'mime-types'
import FormData from 'form-data'
import axios from 'axios'
// modular constants
const aAdmins = JSON.parse(process.env.MYLIFE_HOSTED_MBR_ID)
// modular variables
let AgentFactory
let Globals
// modular class definition
class oAIAssetAssistant {
// pseudo-constructor
#ctx
#file
#mbr_id
constructor(_ctx){
// primary direct assignment
this.#ctx = _ctx
this.#mbr_id = this.#ctx.state.member.mbr_id
// modular direct assignment
if(!AgentFactory) AgentFactory = this.#ctx.AgentFactory
if(!Globals) Globals = this.#ctx.Globals
// secondary direct assignment
this.#file = this.#extractFile(this.#ctx)
// validate asset construction
this.#validateFile()
}
async init(){
await this.#embedFile() // critical step
await this.#enactFile() // critical step
return this
}
// getters
get ctx(){
return this.#ctx
}
get file(){
return this.#file
}
get mbr_id(){
return this.#mbr_id
}
get session(){
return this.#ctx.session?.MemberSession??null
}
// setters
// private functions
async #embedFile(){
console.log(this.file)
console.log('#embedFile() begin')
const _metadata = {
source: 'corporate', // logickify this
source_id: this.file.originalFilename,
url: 'testing-0001', // may or may not use url
author: 'MAHT', // convert to session member (or agent)
}
const _token = process.env.MYLIFE_EMBEDDING_SERVER_BEARER_TOKEN
const _data = new FormData()
_data.append('file', fs.createReadStream(this.file.filepath), { contentType: this.file.mimetype })
_data.append('metadata', JSON.stringify(_metadata))
const _request = {
method: 'post',
maxBodyLength: Infinity,
url: 'http://localhost:8000/upsert-file',
headers: {
'Authorization': `Bearer ${_token}`,
..._data.getHeaders()
},
data : _data
}
return await axios.request(_request)
.then((response) => {
console.log(`#embedFile() finished: ${response.data.ids}`)
return response.data
})
.catch((error) => {
console.error(error.message)
return {'#embedFile() finished error': error.message }
})
}
async #enactFile(){ // vitalizes by saving to MyLife database
console.log('#enactFile() begin')
const _fileContent = {
...this.file,
...{ mbr_id: this.mbr_id }
}
const oFile = new (AgentFactory.file)(_fileContent)
console.log('testing factory',oFile.inspect(true))
return oFile
}
#extractFile(){
if(!this.#ctx.request?.files?.file??false) throw new Error('No file found in request.')
const { lastModifiedDate, filepath, newFilename, originalFilename, mimetype, size } = this.#ctx.request.files.file
return {
...{ lastModifiedDate, filepath, newFilename, originalFilename, mimetype, size, localFilename: `${Globals.newGuid}.${mime.extension(mimetype)}` },
...this.#ctx.request.body
}
}
#validateFile(){
const allowedMimeTypes = [
'application/json',
'application/msword',
'application/pdf',
'application/rtf',
'application/vnd.ms-powerpoint',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'application/vnd.openxmlformats-officedocument.presentationml.presentation',
'text/csv',
'text/html',
'text/markdown',
'text/plain',
]
// reject size
let _mbr_id = this.#ctx.state.member.mbr_id
let _maxFileSize = (aAdmins.includes(_mbr_id) || _mbr_id === process.env.MYLIFE_SERVER_MBR_ID)
? process.env.MYLIFE_EMBEDDING_SERVER_FILESIZE_LIMIT_ADMIN
: process.env.MYLIFE_EMBEDDING_SERVER_FILESIZE_LIMIT
if (this.#file.size > _maxFileSize) throw new Error(`File size too large: ${this.#file.size}. Maximum file size is 1MB.`)
// reject mime-type
if (!allowedMimeTypes.includes(this.#file.mimetype)) throw new Error(`Unsupported media type: ${this.#file.mimetype}. File type not allowed.`)
}
}
// exports
export default oAIAssetAssistant
2 changes: 2 additions & 0 deletions inc/js/agents/system/connector-assistant.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// connector for external resources
// - cloud services (dropbox, google drive, etc)
3 changes: 3 additions & 0 deletions inc/js/agents/system/dom-assistant.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/*
A dom assistant is able to retrieve and pre-consume src html/js and reinterpret according to member's consent preferences. Essential for any ux-agent to function. It would alter the content and/or issue js post-load content (at some temp-created consume-once endpoint [i.e., if failure, alert security]) to alter the page.
*/
Loading

0 comments on commit dbce4b3

Please sign in to comment.